Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Jump Game (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an array of integers nums. You start at the first index of the array and each element in nums represents the maximum number of steps you can jump forward from that position.

Return true if you can reach the last index, or false otherwise.

Examples

Example 1

  • Input: nums = [1, 2, 3, 4, 5]
  • Expected Output: true
  • Justification: Starting at index 0, you can jump 1 step to index 1. From index 1, you can jump 2 steps to index 3. From index 3, you can jump 1 steps to the last index (4). Therefore, it is possible to reach the end.

Example 2

  • Input: nums = [2, 0, 2, 0, 1]
  • Expected Output: true
  • Justification: Starting at index 0, you can jump 2 steps to index 2. From index 2, you can jump 2 steps to the last index (4). Therefore, it is possible to reach the end.

Example 3

  • Input: nums = [1, 0, 1, 0]
  • Expected Output: false
  • Justification: Starting at index 0, you can jump 1 step to index 1. However, index 1 has a value of 0, which means you cannot move forward from there. Therefore, it is impossible to reach the end.

Constraints:

  • 1 <= nums.length <= 10<sup>4</sup>
  • 0 <= nums[i] <= 10<sup>5</sup>

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible