Fewest Turns to Route a Wavelet Through a Faulty Core Mesh
Last updated: November 29, 2026
Quick Overview
Given a 2D mesh of cores where '#' marks a faulty core, find a path from a source core to a destination core using 4-directional moves that minimizes the number of direction changes. Return -1 if no path exists.
Cerebras
November 29, 20260
0
0 solved
Given a 2D mesh of cores where '#' marks a faulty core, find a path from a source core to a destination core using 4-directional moves that minimizes the number of direction changes. Return -1 if no path exists.
On a 2D fabric, a route that changes direction needs extra router configuration at each turn, so compiler and routing engineers care about turn count, not just hop count. The interviewer wants to see you model state as (cell, direction) and use 0-1 BFS rather than plain BFS.
What the Interviewer Expects
- Recognizes that turn count depends on incoming direction, so state is (row, col, dir)
- Uses 0-1 BFS (deque) or Dijkstra with edge weights 0 and 1
- Handles the start correctly (first move is free in any direction)
- Handles blocked source or destination
- Gives O(4RC) complexity
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
- Minimize turns first, then hops as a tiebreak: what changes?
- What if some links (not cores) are faulty?
- How would you route many messages so no link is overloaded?
- Why do hardware routers often prefer dimension-ordered (XY) routing?
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 of R rows and C columns, cells '.' (good) or '#' (faulty). Moves are up, down, left, right onto good cells. Cost is the number of times direction changes. Starting direction is free. Output the m...
High-Level Design
Plain BFS on cells fails because two paths arriving at the same cell from different directions have different futures. So the state is (r, c, d), the cell plus the direction we arrived in. Continuing ...