← Uptime Crew Interview Insights
I knew the base problem and went straight for binary search plus BFS, which felt clean.
Reframe the problem as a maximin path problem: binary search on the safeness score S, and for each S check if a path exists using only cells with distance ≥ S. Then among paths achieving the maximum S, find the shortest via BFS. This combines binary search, BFS, and careful tie-breaking.
Pro tip: Precompute distances to nearest thief using multi-source BFS to avoid O(n^4) checks, and when binary searching, use the fact that the answer is one of the precomputed distances to reduce search space.
Confirm grid size, thief positions, and that Manhattan distance is used. Precompute for each cell the distance to the nearest thief using multi-source BFS from all thief cells.
Binary search over possible safeness values (from 0 to max distance). For each candidate S, check if there is a path from start to end using only cells with distance ≥ S.
For a given S, run BFS from start to end on the subgraph of allowed cells. If reachable, S is feasible; else not.
Once the maximum feasible S is found, run BFS again on allowed cells to find the shortest path (minimum number of steps) from start to end.
Discuss time complexity: O(n^2 log D) where D is max distance, and space O(n^2). Handle edge cases like no path, start/end being thieves, or multiple optimal paths.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.