Skip to content

Instantly share code, notes, and snippets.

@vaguecoder
Last active February 23, 2022 16:13
Show Gist options
  • Save vaguecoder/d726896ca361cf73d5ff0d7ba341decb to your computer and use it in GitHub Desktop.
Save vaguecoder/d726896ca361cf73d5ff0d7ba341decb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def distance(start:int, blocks:list) -> int:
frog1, frog2 = start, start
for i in range(start, 0, -1):
if blocks[i-1] < blocks[i]:
break
frog1 = i-1
for i in range(start, len(blocks)-1):
if blocks[i+1] < blocks[i]:
break
frog2 = i+1
return frog2 - frog1 +1
def solution(blocks:list) -> int:
high, index_high = -1, -1
for i, _ in enumerate(blocks):
d = distance(i, blocks)
if d > high:
high = d
index_high = i
return high, index_high
def main():
blocks = [2, 6, 8, 5]
dist, idx = solution(blocks)
print(f"Max distance (if froggies start from index {idx} in {blocks}) = {dist}")
blocks = [1, 5, 5, 2, 6]
dist, idx = solution(blocks)
print(f"Max distance (if froggies start from index {idx} in {blocks}) = {dist}")
blocks = [1, 1]
dist, idx = solution(blocks)
print(f"Max distance (if froggies start from index {idx} in {blocks}) = {dist}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment