Directional Tiles: Find a Valid Reconfiguration Path
Updated
Problem statement
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.
So that every solution gives the same path, use 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"]]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_. startandendcontain the same number of red tiles, black tiles, and empty positions.- The returned path follows the search order stated above.
More Duolingo Phone Screen questions
- Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
- Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
- Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
- Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
- Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
- Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
- Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
- User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
- Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
- Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
Similar questions at other companies
- Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Deterministic Depth-First Graph TraversalWaymo · PHONE SCREENWaymo interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Count Prefix Paths in a Character GraphGoogle · PHONE SCREENGoogle interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- Detonate Bombs with Chain ReactionsAirbnb · PHONE SCREENAirbnb interview questions
- All Paths From Source to TargetBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Report Island Areas in Discovery OrderSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Generate All Contiguous Protein ChainsBenchling · PHONE SCREENBenchling interview questions
- All Paths for a Rat in a MazeAdobe · PHONE SCREENAdobe interview questions