Greedy Algorithms - Jump Game (Can Reach End?)
The following code attempts to solve the Jump Game problem. Identify the line that contains a subtle bug that causes incorrect results on some inputs.
def canJump(nums):
maxReach = 0
for i, jump in enumerate(nums):
# Bug: missing check if current index is beyond maxReach
maxReach = max(maxReach, i + jump)
if maxReach >= len(nums) - 1:
return True
return False
