HTTP Request Redirection
Problem statement
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:
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].
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- Worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.