Directional Tiles: Find a Valid Reconfiguration Path
Reported by candidates from Duolingo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the tiles and this Duolingo OA, reported in October 2022, is a graph search in disguise. Every board string is a node, every legal move or jump is an edge, and you're hunting for a path from start to end. With a board of at most 12 cells, the state space stays small. The catch is the judging rule: you must run DFS in a fixed order, so a clean BFS answer will fail the tests. If you blank on the move ordering during the live OA, StealthCoder can sit invisibly on your screen as a safety net. Know the shape first.
The problem
A one-dimensional board contains red tiles R, black tiles B, and empty positions _. A red tile may move only to the right. A black tile may move only to the left. A tile may move one position into an adjacent empty position. A tile may instead jump over exactly one tile of the other color and land in the empty position immediately beyond it. Given start and end, return a valid sequence of board states that transforms start into end. Include both endpoint states. The path does not need to be globally shortest. For deterministic judging, perform depth-first search with a visited-state set. At each state, inspect tile positions from left to right; for a tile, consider its one-step move before its two-step jump. Return the first path found by that search. If no path exists, return an empty array. Function findTilePath(start: String[], end: String[]) → String[][] Examples Example 1 start = ["R","_","B","B"] end = ["B","_","B","R"] return = [["R","_","B","B"],["_","R","B","B"],["B","R","_","B"],["B","R","B","_"],["B","_","B","R"]] The returned states are exactly the source example. Each transition is either a legal one-step move or a legal jump over one opposite-color tile. Example 2 start = ["R","R","_"] end = ["_","R","R"] return = [["R","R","_"],["R","_","R"],["_","R","R"]] The rightmost red tile moves first, then the remaining red tile moves into the empty position. Constraints 1 <= start.length == end.length <= 12. Every entry is R, B, or _. start and end contain the same number of red tiles, black tiles, and empty positions. The returned path follows the deterministic search order stated above.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Model each board as a state, serialized to a string for the visited set. DFS from start. At each state, scan positions left to right. For each tile, try the one-step move first, then the two-step jump. R moves right only, B moves left only. A jump needs exactly one opposite-color tile in the middle and an empty landing cell. Push the state onto the path, recurse, and pop on failure. Return the first path that reaches end, or an empty array. The common pitfall is swapping in BFS for a shorter path. The statement says shortest isn't required and the judge expects the DFS result. Another trap is forgetting to copy the board before mutating it, or checking the visited set after recursing instead of before. If you blank on the exact ordering in the live OA, StealthCoder is the hedge that gets you unstuck.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Directional Tiles: Find a Valid Reconfiguration Path cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Duolingo's OA.
Duolingo reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Directional Tiles: Find a Valid Reconfiguration Path FAQ
What's the trick in the Duolingo directional tiles problem?+
Treat each board configuration as a graph node and each legal move or jump as an edge. Then run DFS with a visited set of serialized boards. The hard part isn't the algorithm, it's matching the required exploration order exactly.
Can I use BFS instead of DFS here?+
No. The output is judged deterministically against the first path DFS finds, using the stated order. BFS gives a shortest path, which usually differs from the expected answer and fails the tests even though it's a valid transformation.
What order should I try moves in?+
Scan tile positions left to right. For each tile, try the one-step move before the two-step jump. Within that, respect direction: red goes right, black goes left. Keep this order identical in every recursive call or your path will diverge.
How do I handle the visited set and no-path case?+
Serialize each board into a string and mark it visited before exploring its neighbors. If DFS exhausts every reachable state without hitting end, return an empty array. With length at most 12, the reachable state count is small enough for recursion.
How do I prepare for this in 48 hours?+
Write a generic DFS path-finder on a state graph once. Practice generating neighbors, copying state, and backtracking the path. Then test on both examples by hand, checking that your move order reproduces the exact sequences shown.