Fewest Signpost Changes to Route Visitors Across a Campus Grid

Last updated: November 29, 2026

Quick Overview

Each cell of a grid holds a signpost pointing right, left, down or up, and a visitor at the top-left follows the signs. Changing one sign costs 1; return the minimum number of changes so that some route reaches the bottom-right cell.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Each cell of a grid holds a signpost pointing right, left, down or up, and a visitor at the top-left follows the signs. Changing one sign costs 1; return the minimum number of changes so that some route reaches the bottom-right cell.

A Meta onsite question that rewards spotting 0-1 BFS instead of reaching for full Dijkstra. Framed as wayfinding signage on a large campus like Menlo Park. The interviewer checks whether you can turn 'follow the arrow' into zero-cost edges and 'change the arrow' into unit-cost edges.

What the Interviewer Expects
  • Model each cell with four outgoing edges, cost 0 along the sign and 1 otherwise
  • Choose 0-1 BFS with a deque and explain why it matches Dijkstra
  • Allow a node to be re-pushed when its distance improves
  • Keep the code free of off-by-one errors on grid bounds
  • State O(RC) complexity
Key Topics to Cover
0-1 BFS
Deque
Shortest path
Grid graph
Dijkstra
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Why is a plain BFS wrong here?
  • How would you return which signs to change?
  • What if changing a sign had a cell-specific cost?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Grid up to 100 x 100 with values 1 (right), 2 (left), 3 (down), 4 (up).
  • A sign may point off the grid.
  • Return the minimum number of sign changes needed to make a valid route from (0,0) to (R-1,C...
High-Level Design

Build an implicit graph: from each cell, moving in the sign's direction costs 0, and moving in any of the other three directions costs 1 (we change that sign). Edge weights are only 0 or 1, so 0-1 BFS...


Submit Your Answer
Markdown supported