rishu110067

Untitled

Feb 2nd, 2022 (edited)
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # O(n)
  2. def can_reach_last_house(maximum_jump_lengths):
  3.     n = len(maximum_jump_lengths)
  4.     dp = [False]*n
  5.    
  6.     max_reachable_house = 0
  7.     for i in range(0, n):
  8.         if max_reachable_house >= i:
  9.             dp[i] = True
  10.             max_reachable_house = max(max_reachable_house, i + maximum_jump_lengths[i])
  11.    
  12.     return dp[n-1]
  13.  
Add Comment
Please, Sign In to add comment