Can a Hopping Delivery Drone Cross a River Using Only Charging Pads

Last updated: November 29, 2026

Quick Overview

Charging pads sit at sorted positions across a river starting at 0. A drone's first hop is 1 unit, and if its last hop was k units, its next hop must be k - 1, k or k + 1 units forward, landing on a pad. Decide whether it can reach the last pad.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Charging pads sit at sorted positions across a river starting at 0. A drone's first hop is 1 unit, and if its last hop was k units, its next hop must be k - 1, k or k + 1 units forward, landing on a pad. Decide whether it can reach the last pad.

A Google onsite hard where the DP state is a pad plus the incoming hop length, stored sparsely. Interviewers look for a hash map from position to the set of hop sizes and a complexity argument that keeps the state space bounded.

What the Interviewer Expects
  • Recognize the state needs both position and last hop size
  • Store, for each pad, the set of hop sizes that can arrive there
  • Propagate forward from each pad in sorted order
  • Bound the state space by O(n^2)
  • Explain an early-exit or pruning rule
Key Topics to Cover
1D dynamic programming
Sparse DP states
Hash sets
Frog jump
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 minimum number of hops.
  • The drone can also hop backward.
  • Positions go up to 10^9 but there are only 2000 pads. Is your solution fine?
  • Hop sizes may change by up to d instead of 1.
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: sorted list pads of distinct non-negative integers with pads[0] = 0. The drone starts on pad 0. The first hop must be exactly 1. After a hop of k, the next hop is k - 1, k, or k + 1 and mus...

High-Level Design

Keep arrive[p], the set of hop sizes that can land on pad p. Seed arrive[0] = {0} so the first hop options are -1, 0, 1, of which only 1 is positive. Process pads in increasing position: for each ...


Submit Your Answer
Markdown supported