FastPrepJump Game

Jump Game

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

You are given an array nums. You start at index 0, and nums[i] is the maximum number of positions you may jump forward from index i.

Return true if you can reach the final index. Otherwise, return false.

Function

canJump(nums: int[]) → boolean

Examples

Example 1

nums = [2,3,1,1,4]return = true

Jump from index 0 to index 1, then from index 1 to the final index.

Example 2

nums = [3,2,1,0,4]return = false

Every route reaches index 3, whose jump length is zero, before the final index.

Example 3

nums = [0]return = true

The starting index is already the final index.

Constraints

  • 1 <= nums.length <= 100000.
  • 0 <= nums[i] <= 100000.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean canJump(int[] nums) {
    // Write your code here.
}
nums[2,3,1,1,4]
expectedtrue
Checking account…