Shortest Path Across a Moderation Grid With Limited Overrides
Last updated: November 29, 2026
Quick Overview
A moderation review grid has open cells (0) and blocked cells (1) that normally require escalation. Starting at the top-left, reach the bottom-right with 4-directional moves, where you may pass through at most k blocked cells using overrides. Return the minimum number of moves, or -1.
TikTok
November 29, 20260
0
0 solved
A moderation review grid has open cells (0) and blocked cells (1) that normally require escalation. Starting at the top-left, reach the bottom-right with 4-directional moves, where you may pass through at most k blocked cells using overrides. Return the minimum number of moves, or -1.
TikTok onsite coding rounds like grid BFS problems with an extra resource dimension, and trust and safety teams think in terms of limited escalation budgets. The interviewer is checking that you expand the state to (row, col, overrides_left) and keep BFS correct with that richer state.
What the Interviewer Expects
- Explains why plain visited-by-cell BFS is wrong when the override budget differs between paths
- Models state as (r, c, remaining overrides) and runs BFS over it
- Prunes with the best remaining budget seen per cell
- Notes the shortcut when k is at least the Manhattan distance minus one
- Gives O(R * C * k) time and space
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 overrides have different costs per cell (weighted)?
- How would you return the actual path?
- How does the approach change if moves can also be diagonal?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: grid of 0/1, integer
k >= 0. Start and end cells may be blocked; entering a blocked cell spends one override, and the start costs one if it is blocked. - Output: minimum steps from (0,0) to...
High-Level Design
Two paths can reach the same cell with different numbers of overrides left, and the one with more left may finish where the other cannot. So the BFS state is (r, c, rem).
Pruning: keep best[r][c]...