Shortest Route Through a Traced Maze
Updated
Problem statement
Duo records one route through a maze as a list path whose entries are "north", "east", "south", or "west". The route begins at coordinate (0, 0).
Every cell visited by the recorded route is known to be passable. No unvisited cell may be inferred to be passable. Two known cells are connected when they are orthogonally adjacent.
The source guarantees that there is exactly one shortest route through the known cells from (0, 0) to the recorded route's final coordinate. Return that route as a list of direction strings. The result may equal path when the recorded route is already optimal.
Function
shortestTracedMazeRoute(path: String[]) → String[]Examples
Example 1
path = ["south","east","east","south","south","west","west","east","east","south"]return = ["south","east","east","south","south","south"]The recorded walk visits cells that create a direct vertical connection near the end. The unique shortest known route removes the west-east detour and uses six moves instead of ten.
Constraints
1 <= path.length <= 100000.- Every entry is exactly
"north","east","south", or"west". - The source guarantees exactly one shortest route through the visited cells from the origin to the final coordinate.
- The returned route is never longer than
path.
Source note: The added source image shows the maze prompt, recorded route, and shorter-route example from an independent Duolingo OA report.
More Duolingo interview questions
- Bouncing Square Reaches a Screen CornerOA · Seen Dec 2024
- Most-Read Page Across Every Valid StorylineOA · PHONE SCREEN · Seen Oct 2022
- Rank Common Translation MistakesOA · Seen Sep 2022
- Count Distinct Word MeaningsOA · Seen Sep 2021
- Count Legal Outfit CombinationsOA · Seen Sep 2021
- 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
Similar questions at other companies
- Find Minimum City HopsAmazon · OA
- Find a Directed Resource Access PathCoreWeave · PHONE SCREEN
- Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
- Shortest Path from an Encoded GraphIntuit · OAIntuit interview questions
- Longest Distance in a Frequency-Limited NetworkBloomberg LP · OABloomberg LP interview questions
- Fraud Ring SizeStripe · OAStripe interview questions
- Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
- Grid ExplorationIMC Trading · OAIMC Trading interview questions
- Shortest Path in an Unweighted GraphPeopleStrong · OAPeopleStrong interview questions
- Minimum Genetic MutationBenchling · OABenchling interview questions