DSA interview question
A platformer level is a row of tiles, and tile i lets the player jump up to nums[i] tiles forward. Starting on the first tile, can the player reach the last one? Exploring every jump is exponential. But reachability is monotone: if tile j is reachable, every tile before it is too. So you only need the farthest reachable index so far. Walk forward while you're inside that reach, extending it with i + nums[i]. If you ever stand beyond it, you're stuck.
Example: [2, 3, 1, 1, 4] → true; [3, 2, 1, 0, 4] → false.
bool canJump(const vector<int>& nums);
| Input | Output | Explanation |
|---|---|---|
[2, 3, 1, 1, 4] | true | 0 → 1 → 4 |
[3, 2, 1, 0, 4] | false | Every path lands on the 0 at index 3 |
[0] | true | Already at the end |
[1, 0, 1] | false | Stuck at index 1 |
[2, 0, 0] | true | Jump straight to the end |
(Confirm: jumps can be any length from 1 to nums[i]; values are non-negative.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in