Greedy Algorithms8 sections · 316 units
Open in Course

Jump Game - Implementation

The code

function canJump(nums)
 furthest := 0
 for i from 0 to length of nums - 1
 if i > furthest then
 return false
 furthest := max(furthest, i + nums[i])
 return true

Time: O(n)O(n). Space: O(1)O(1).