Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # O(n)
- def can_reach_last_house(maximum_jump_lengths):
- n = len(maximum_jump_lengths)
- dp = [False]*n
- max_reachable_house = 0
- for i in range(0, n):
- if max_reachable_house >= i:
- dp[i] = True
- max_reachable_house = max(max_reachable_house, i + maximum_jump_lengths[i])
- return dp[n-1]
Add Comment
Please, Sign In to add comment