Reported July 2026
Amazonhash table

HTTP Request Redirection

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon reported this one in July 2026, and the trap is sitting in the input size. You've got a start point, a list of redirects, and a rule to jump to the nearest unvisited server along a diagonal. Scanning every server for every record is O(n * m), and that's the brute force the constraints are built to punish. The real pattern is hashing servers by diagonal and keeping them ordered. If you blank on the data structure during the OA, StealthCoder runs invisibly as a safety net, but the idea below is short enough to own tonight.

The problem

Amazon engineers are investigating an HTTP request that is redirected among servers.
There are n servers on an infinite two-dimensional plane. The coordinates of server i are given by locations[i] = [x, y]. The request starts at locations[0], and that server is marked as visited.
Each value in redirectRecords specifies one redirect direction from the current server (a, b). In every formula below, Z is an arbitrary positive integer:
Direction 1: (a, b) -> (a + Z, b + Z).
Direction 2: (a, b) -> (a + Z, b - Z).
Direction 3: (a, b) -> (a - Z, b + Z).
Direction 4: (a, b) -> (a - Z, b - Z).
Process the redirect records in order. For each record, redirect the request to the nearest server in the specified direction that has not previously been visited. If no eligible server exists in that direction, skip that redirect. Whenever the request reaches a server, mark it as visited.
Return the coordinates [x, y] of the server holding the request after all redirect records have been processed.

Function
findFinalServer(locations: int[][], redirectRecords: int[]) → int[]

Examples
Example 1
locations = [[3,4],[1,2],[7,8],[5,6]]
redirectRecords = [1,4]
return = [1,2]
The request starts at [3, 4]. Direction 1 points toward both [5, 6] and [7, 8], so the nearest unvisited server is [5, 6].
Direction 4 points back toward [3, 4] and then [1, 2]. Because [3, 4] has already been visited, the request moves to [1, 2].

Reported by candidates. Source: FastPrep

Pattern and pitfall

Each direction is a diagonal. Directions 1 and 4 lie on the line where x - y is constant. Directions 2 and 3 lie on the line where x + y is constant. So group servers into hash maps keyed by x - y and by x + y, and sort each group by x. From the current server, binary search in the right group and walk toward the nearest unvisited neighbor in the right direction. Visited servers must be skipped permanently, so remove them from every group they belong to, using a linked-list style prev/next pointer or a sorted structure with deletion. The common pitfall is forgetting a server lives in both of its diagonals, so marking it visited in only one group lets it come back. Another trap is treating the start server as available. A skipped redirect leaves the position unchanged. Amortized, this runs in roughly O((n + m) log n). StealthCoder is the hedge if the deletion bookkeeping falls apart mid-assessment.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill HTTP Request Redirection 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

HTTP Request Redirection FAQ

What's the trick in the Amazon HTTP Request Redirection problem?+

Recognize that each direction is a diagonal. Group servers by x - y and x + y, sorted by x. Then the nearest server in a direction is just the adjacent entry in a sorted list, not a full scan of all servers.

Why does brute force fail here?+

For every redirect record you'd scan all n servers to find the nearest valid one on the diagonal. With large n and many records, that's O(n * m) and likely times out. Diagonal grouping cuts each step to a lookup plus a small walk.

How do I handle visited servers correctly?+

A server sits on two diagonals, one by x - y and one by x + y. Mark it visited globally and remove it from both groups, or use a linked list with prev/next pointers per diagonal. Missing either one lets a visited server get picked again.

What happens when no server exists in the direction?+

You skip that record and stay at the current server. Don't change the position and don't mark anything. Watch out for the case where the only remaining candidates on that diagonal are already visited, which also counts as none.

How do I prepare for this in 48 hours?+

Practice grouping points by diagonal keys, then sorted-neighbor lookup with deletion. Write the solution once with a sorted list per diagonal and bisect or a pointer approach. Test on the example where the start server is revisited by a backward direction.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it