Fewest Relay Hops to Push a Live Stream Across Edge Nodes

Last updated: November 29, 2026

Quick Overview

Edge nodes are arranged in a line and node i can forward a live stream to any of the next reach[i] nodes. Return the minimum number of hops from node 0 to the last node, or -1 if it cannot be reached.

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

0

0

0 solved


Edge nodes are arranged in a line and node i can forward a live stream to any of the next reach[i] nodes. Return the minimum number of hops from node 0 to the last node, or -1 if it cannot be reached.

Douyin LIVE pushes ingest streams through chains of relay nodes before reaching viewers' edge caches, and fewer hops means lower latency. The interviewer wants the linear greedy (a BFS by layers on an array) rather than a quadratic DP, and a clean argument for why it is optimal.

What the Interviewer Expects
  • Recognize the problem as BFS layers over index ranges
  • Track the current layer end and the farthest reachable index
  • Increment hops only when the current layer is exhausted
  • Detect unreachability when an index exceeds the farthest reach
  • Prove optimality informally
Key Topics to Cover
greedy
BFS by layers
arrays
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 relay path, not just the count.
  • What if each hop also has a latency cost and you minimize total latency?
  • How would the answer change if nodes can also forward backward?
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 is a list of non-negative integers. Output is the minimum hops to index n-1, or -1. A single node needs 0 hops. Values can be 0, meaning the node cannot forward....

High-Level Design

Think of hop k as the set of indexes reachable with exactly k hops; that set is a contiguous range. While scanning the current range, compute the farthest index any of them can reach. When the scan hi...


Submit Your Answer
Markdown supported