Skip to content

Instantly share code, notes, and snippets.

@priyankvex
Created May 4, 2019 11:42
Show Gist options
  • Save priyankvex/0f658bba589de0f5e131a640f3d8b8e9 to your computer and use it in GitHub Desktop.
Save priyankvex/0f658bba589de0f5e131a640f3d8b8e9 to your computer and use it in GitHub Desktop.
Jump game
"""
https://scammingthecodinginterview.com
Week 3: Greedy
Problem: 1
"""
from typing import List
class Solution(object):
def solve(self, a: List[int]) -> bool:
n = len(a)
index = 0
reach = 0
while index < n and index <= reach:
reach = max(reach, index + a[index])
if reach >= n-1:
break
index += 1
return reach >= n-1
if __name__ == "__main__":
a = [3, 2, 1, 0, 4]
ans = Solution().solve(a)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment