PPractick

DSA interview question

Jump Game

Easy · Algorithms · Topics: greedy, array

The problem

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.

Function signature

bool canJump(const vector<int>& nums);

Test cases

InputOutputExplanation
[2, 3, 1, 1, 4]true0 → 1 → 4
[3, 2, 1, 0, 4]falseEvery path lands on the 0 at index 3
[0]trueAlready at the end
[1, 0, 1]falseStuck at index 1
[2, 0, 0]trueJump straight to the end

(Confirm: jumps can be any length from 1 to nums[i]; values are non-negative.)

How interviewers phrase it

Clarifying questions to ask

  1. Can I jump shorter than nums[i]? (Yes, any length up to it.)
  2. Is a single-element array already at the goal? (Yes.)
  3. Can values be 0? (Yes, and zeros create traps.)

Follow-ups to expect

  1. "Why is the farthest reach enough?"
  2. "When do you fail?"
  3. "Backward greedy?"
  4. "DP alternative?"
  5. "Complexity?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in