Fewest Relay Hops to Push an Update to the Last Edge Node

Last updated: November 29, 2026

Quick Overview

Edge nodes sit in a line; node i can forward an update to any node up to reach[i] positions ahead. Return the minimum number of hops for an update starting at node 0 to reach the last node, or -1 if it cannot.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Edge nodes sit in a line; node i can forward an update to any node up to reach[i] positions ahead. Return the minimum number of hops for an update starting at node 0 to reach the last node, or -1 if it cannot.

Framed around pushing configuration through a chain of edge caches in Google's network, this is a Google technical screen greedy problem. The interviewer wants you to see it as BFS over levels and then collapse that to an O(n) greedy with a current-frontier and next-frontier boundary.

What the Interviewer Expects
  • Recognizes the BFS-by-levels structure
  • Implements the O(n) greedy with current end and farthest reach
  • Detects unreachability when the frontier stops growing
  • Explains why greedy equals BFS here
  • Avoids the O(n^2) DP
Key Topics to Cover
Greedy
Implicit BFS
Arrays
Jump Game
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 sequence of relay nodes used.
  • What if each hop has a different cost and you minimize total cost?
  • What if reach values change over time and you get many queries?
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 non-negative integers, length n >= 1.
  • Output: minimum hops from index 0 to index n-1, or -1 if unreachable.
  • n can be large (10^5), so O(n^2) DP is too slow....
High-Level Design

Think of BFS: level 0 is node 0; level 1 is every node node 0 can reach; level 2 is every node reachable from level 1, and so on. Because reachable sets are always contiguous ranges, we do not need a ...


Submit Your Answer
Markdown supported