← LinkedIn Interview InsightsAI Engineer

LinkedIn·AI Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

LinkedIn AI Engineer interview with a classic optimization problem that sounds straightforward but has a real proof component attached to it. The coding part is manageable but they wanted the math too.

Questions Asked (1)

Q1

N people are standing at known positions on a 1-D road. Find a meeting point that minimizes the total sum of absolute distances from all people to that point. Prove why your chosen point is optimal and implement a solution.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the answer was the median but fumbled the proof a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and constraints, then explain that the optimal meeting point is the median of the positions. Prove optimality using the convexity of the sum of absolute distances and the subgradient condition, and implement an O(N log N) solution by sorting and picking the median (or O(N) with quickselect).

Pro tip: Mention that for even N, any point between the two middle positions is optimal, and discuss trade-offs like sorting vs. quickselect and handling large inputs or streaming data.

1. Clarify the problem and constraints

Confirm that positions are on a line, distances are absolute, and ask about input size, duplicates, and whether the meeting point must be at a person's position.

2. State the optimal solution

Explain that the median minimizes the sum of absolute deviations, and for even N, any point between the two middle values works.

3. Prove optimality

Use a convexity argument: the sum of absolute values is convex, and the subgradient contains zero exactly at the median; or use a pairwise exchange argument.

4. Implement the solution

Sort the array and pick the middle element (O(N log N)), or use quickselect for O(N) average time; handle edge cases like N=1 or empty input.

5. Discuss trade-offs and extensions

Compare sorting vs. quickselect, mention streaming/online median maintenance, and note that for weighted distances the weighted median is optimal.

Key Points to Mention

  • Median minimizes sum of absolute deviations
  • Proof via convexity and subgradient condition
  • For even N, any point between the two middle positions is optimal
  • Time complexity: O(N log N) with sorting, O(N) average with quickselect
  • Edge cases: N=1, duplicates, empty input
  • Extension: weighted median for weighted distances

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.