Diagonal Nearest-Unvisited Redirect Simulation

Asked at Amazon · Coding Questions · Difficulty: Hard

There are `n` servers at `locations[i] = [x_i, y_i]` on a plane, and a list `redirect_records` of directions (each in `1..4`). Starting at `locations[0]` (marked visited), process each direction: consider only servers on the corresponding diagonal ray from the current server with step `Z >= 1`, redirect to the **nearest unvisited** such server (mark it visited); if none exists, stay. Directions from `(a,b)`: 1 → `(a+Z, b+Z)`; 2 → `(a+Z, b-Z)`; 3 → `(a-Z, b+Z)`; 4 → `(a-Z, b-Z)`. A server cannot be visited twice. Return the final coordinates `[x, y]`.

Loading the problem…