Pick a Meetup Cell Minimizing Total Walking for All Friends
Last updated: November 29, 2026
Quick Overview
A grid marks with 1 the cells where friends live. Choose any meeting cell that minimizes the sum of Manhattan distances from every friend, and return that minimum total.
Meta
November 29, 20260
0
0 solved
A grid marks with 1 the cells where friends live. Choose any meeting cell that minimizes the sum of Manhattan distances from every friend, and return that minimum total.
A Meta onsite question where the brute force is easy and the insight is mathematical, framed around suggesting a meetup spot for a Facebook Events group. Interviewers check that you separate the Manhattan distance into independent row and column parts and use the median of each.
What the Interviewer Expects
- Separate Manhattan distance into row and column components
- Show that the median minimizes the sum of absolute deviations
- Collect rows and columns in sorted order without explicit sorting
- Compute the total with two pointers instead of locating the median
- Compare with the O((RC)^2) brute force
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if some cells are obstacles and people must walk around them?
- What if each friend has a weight, such as group size?
- Can you solve it if the meeting point must be one of the homes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Grid up to 200 x 200 with at least one friend.
- No obstacles, so walking distance is Manhattan distance.
- The meeting point can be any cell....
High-Level Design
Total distance is sum |r_i - r| + sum |c_i - c|, and the two sums are independent, so minimize each separately. For a 1D set of points, any median minimizes the sum of absolute deviations: moving th...