id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

amjadm@miamioh.edu project5 > canJump
prev  |  next  |  chance

You are given an integer array nums where each element represents your maximum jump length at that position. You start at index 0, and your goal is to determine whether you can reach the last index of the array. From any position i, you may jump to any of the next nums[i] indices, that is, any index from i + 1 to i + nums[i]. You can only move forward, and you cannot jump beyond the array bounds. Return true if it is possible to reach the last index starting from index 0, otherwise return false. For example, if nums = {2,3,1,1,4}, you can jump from index 0 to 1, and then from index 1 to index 4, which is the last index, so the output is true. If nums = {3,2,1,0,4}, you will always get stuck at index 3 because its maximum jump length is 0, and you cannot reach index 4, so the output is false. You must solve this in linear time.


canJump([2, 3, 1, 1, 4]) → true
canJump([3, 2, 1, 0, 4]) → false
canJump([0]) → true

...Save, Compile, Run (ctrl-enter)

public boolean canJump(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 310

Copyright Nick Parlante 2017 - privacy