Fewest Sortation Center Hops to Route a Package to Its Destination

Last updated: November 29, 2026

Quick Overview

Sortation centers lie in a line, and from center i a package can be forwarded to any center up to reach[i] positions ahead. Starting at center 0, return the minimum number of forwards needed to reach the last center, assuming it is reachable.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Sortation centers lie in a line, and from center i a package can be forwarded to any center up to reach[i] positions ahead. Starting at center 0, return the minimum number of forwards needed to reach the last center, assuming it is reachable.

An Amazon phone screen greedy question. BFS works but the interviewer wants the O(n), O(1) space level-by-level greedy, and an explanation of why it is BFS in disguise.

What the Interviewer Expects
  • Sees the BFS layers over a line
  • Tracks current layer end and farthest reach
  • Increments hops when crossing the layer end
  • Stops before processing the last index
  • Handles n = 1
Key Topics to Cover
greedy
BFS layers
array traversal
reachability
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the actual hop sequence.
  • What if some centers are closed (reach 0) and the last may be unreachable?
  • What if hops have different costs?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list reach of nonnegative integers, length n >= 1, last index reachable. Output: min number of jumps from 0 to n - 1....

High-Level Design

Think of BFS: layer 0 is center 0, layer 1 is everything reachable in one hop, and so on. Over a line, each layer is a contiguous range. Scan i from 0 to n - 2, keeping `farthest = max(farthest, i + r...


Submit Your Answer
Markdown supported