← Questions
Best meeting point on a grid
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Waymo's technical phone screen and at Applied Intuition, last asked May 2026. It tests grids, bfs and math.
A grid has blocked cells, empty cells and marked cells (people or buildings). You move up, down, left or right through non-blocked cells, one unit per step. Find the cell whose total shortest-path distance to all marked cells is smallest.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
best_meeting_cell(grid: list[list[int]]) -> tuple[int, tuple[int, int]] | int—-1is blocked,0empty,1marked. Any non-blocked cell may be the meeting cell. Return(total_distance, (row, col)), with ties broken by the smallest(row, col), or-1if no cell can reach every marked cell.
Example
best_meeting_cell([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]) -> (4, (1, 1)) # distances 2 + 0 + 2
best_meeting_cell([[1, -1, 0, 0],
[0, -1, 0, 1],
[0, 0, 1, 0]]) -> (6, (2, 2)) # distances 4 + 2 + 0, around the wall
best_meeting_cell([[1, -1, 1]]) -> -1 # the wall splits the marks
Constraints
-
1 <= rows, cols <= 50; at least one marked cell.
Clarifying questions
- Can people walk through marked cells, or must the meeting point be an empty cell that buildings block (a different variant)?
- Are there obstacles at all?
- How are ties broken?
- What if some marked cell can't reach the others?
What a strong answer covers
- Brute force first: BFS from every candidate cell, O((R·C)²).
- Reversing it: one BFS from each marked cell, summing distances into a grid and counting how many marks reached each cell; O(k · R · C), much better when marks are few.
- Why a single multi-source BFS is not enough (it gives the distance to the nearest mark, not the sum).
- With no obstacles and Manhattan distance, rows and columns separate: the median row and median column are optimal, O(k log k) or O(R + C) with counting.
- Unreachable marks detected by the reach counts.
Follow-ups
- Marked cells are buildings you can't walk through and the meeting cell must be empty land.
- Minimize the maximum distance instead of the sum.
- Marks have weights (how many people live there).
Where it's asked
- Waymo · Technical phone screen · Last asked May 202645 min · Coding: a classic algorithm problem or an original, under-specified problem framed around self-driving
- Applied Intuition · Technical phone screen · Last asked Sep 202545 min · Live coding in CoderPad; the language can be fixed by the role (Python, C++, or C for embedded)
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding

