Can a Hopping Robot Reach the Last Shelf in an Aisle
Last updated: November 29, 2026
Quick Overview
A warehouse robot stands at shelf 0 of an aisle, and shelf i lets it hop forward any distance from 1 to jump[i]. Decide whether the robot can reach the last shelf.
0
0
0 solved
A warehouse robot stands at shelf 0 of an aisle, and shelf i lets it hop forward any distance from 1 to jump[i]. Decide whether the robot can reach the last shelf.
A Google phone-screen classic that separates candidates who write an O(n^2) reachability DP from those who compress it to a running farthest-reach value. The interviewer usually accepts the DP first and then asks you to optimize.
What the Interviewer Expects
- State the reachability DP: reachable[i] if some earlier reachable j can jump to i
- Notice reachable shelves always form a prefix
- Collapse the DP into a single farthest-reach variable
- Stop early once a gap is found or the end is covered
- Argue correctness, not just give code
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the minimum number of hops needed.
- What if some shelves are blocked and cannot be landed on?
- What if hops can go backward as well as forward?
- Count the number of distinct hop sequences that reach the end.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list jump of non-negative integers, length n >= 1. From index i the robot may move to any index in i+1 .. i+jump[i]. Output True if index n - 1 is reachable from index 0. A zero means the r...
High-Level Design
The direct DP is reachable[0] = True and reachable[i] = any(reachable[j] and j + jump[j] >= i for j < i), which is . The key observation is that the set of reachable indices is always a pr...