Epic Systems Interview Question
SDE1sCountry: United States
Interview Type: Written Test
def canJump(nums):
"""
:type nums: List[int]
:rtype: bool
"""
max_reach = 0 # initialize the maximum reachable index
for i in range(len(nums)):
if max_reach >i :
continue
else:
max_reach = i + nums[i-1]
if nums[i-1] >(len(nums) - i) or nums[i-1] ==0:
print(len(nums) - i, nums[i-1])
return False
# If we have reached here, that means the last index is reachable
return True
print(canJump([2, 3, 1, 1, 4])) # Expected output: True
print(canJump([3, 2, 1, 0, 4])) # Expected output: False
Please elaborate your questions
- denizen April 22, 2015