You must develop an algorithm to navigate a car through an optimal path while hitting every flag in the graph.
You can gain points by:
- Giving a valid path that hits all flags
- Giving the optimal path
Note: All tests run back-to-back under a single total time limit. To be scored, your solution must return an output—correct or not—for every test case within that total time. If the total time limit is exceeded, the entire submission receives 0 points.
You can add your own test paths to user-defined-tracks.json.
Input
You will be given a 2D track in the form of a two-dimensional array. You will be given a starting square, the location of the flags, and the navigable squares in the track.
Spaces within the track can be one of the following values:
S— The starting spaceF— Flags (navigable)1— Navigable space0— Out of bounds space
An example input (Simple track):
Output
You must return an object with an array called moves. The accepted values are RIGHT, LEFT, UP, and DOWN.
The optimal path for the Simple Track can be solved in 13 moves:
This Netflix OA problem asks you to find a path on a 2D track that starts at S, visits every flag F, and returns the movement sequence using RIGHT, LEFT, UP, and DOWN. The key challenge is balancing path validity, optimality, and strict total time limits across many test cases. A common solution is to run BFS between the start and each flag to build pairwise shortest distances, then solve the visiting-all-flags problem with bitmask DP or TSP-style dynamic programming when the number of flags is small. For larger cases, heuristic or greedy fallback strategies may be needed to keep the solution fast enough.