← Amazon Interview Insights

Amazon·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Amazon SWE coding round, one problem the whole session. It was a ring-graph shortest path thing dressed up as a drone delivery scenario. Felt manageable once I saw through the theme, but the edge cases kept me honest.

Questions Asked (1)

Q1

You have n hubs arranged in a ring, each connected to its neighbors by corridors with given lengths. Given a route as an ordered list of hub indices, find the total minimum distance a drone travels by always taking the shorter arc between consecutive stops.

Algorithms & Data Structures
Author's notes

The ring structure is what makes it click.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First clarify the problem constraints and assumptions, then design an efficient algorithm using prefix sums to compute distances in O(1) per query. Explain how to handle the circular nature by comparing clockwise and counterclockwise distances, and analyze time and space complexity.

Pro tip: Mention that you would precompute prefix sums of corridor lengths to answer each distance query in constant time, and discuss edge cases like when the route has only one hub or when the shorter arc is ambiguous (equal distances).

1. Clarify the problem

Ask questions to confirm: Are the hubs numbered 0 to n-1 in order? Are corridor lengths positive? Can the route contain repeated hubs? Is the drone allowed to pass through other hubs? Confirm that 'shorter arc' means the minimum of clockwise and counterclockwise distances.

2. Preprocess for fast distance queries

Compute prefix sums of the corridor lengths around the ring so that the clockwise distance between any two hubs can be found in O(1). Also compute the total perimeter length.

3. Compute distance between consecutive stops

For each pair of consecutive hubs in the route, calculate the clockwise distance using prefix sums, then the counterclockwise distance as total perimeter minus clockwise. Take the minimum of the two.

4. Sum and return the total

Accumulate the minimum distances for all consecutive pairs to get the total minimum distance the drone travels. Handle edge cases such as a route with fewer than two hubs (return 0).

5. Analyze complexity and test

State that preprocessing takes O(n) time and O(n) space, and each query takes O(1), so total time is O(n + m) where m is the route length. Walk through a small example to verify correctness.

Key Points to Mention

  • Prefix sums for O(1) distance queries
  • Circular distance calculation: min(clockwise, total_perimeter - clockwise)
  • Handling edge cases: route length < 2, equal distances, repeated hubs
  • Time and space complexity: O(n) preprocessing, O(1) per query, O(n + m) total
  • Assumption that hubs are numbered sequentially around the ring
  • Modular arithmetic for index wrapping (e.g., from last hub to first)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.