Problem · Array

HTTP Request Redirection

MediumAmazon logoAmazonFULLTIMEOA
See Amazon hiring insights

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:

The problem statement continues
Pro

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].

Original screenshot from the interview report
Pro
FastPrep Pro
Reported in 1 Amazon interview this week

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
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

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
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week