Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Last active February 24, 2023 14:52
Show Gist options
  • Save NicolaM94/7dc6773887badbb8d4563bf74fa544b0 to your computer and use it in GitHub Desktop.
Save NicolaM94/7dc6773887badbb8d4563bf74fa544b0 to your computer and use it in GitHub Desktop.
Forward solution
def forwardSolution (buildings):
haveSight = [buildings[0]]
for b in buildings[1:]:
if b > haveSight[0]:
haveSight = [b]
continue
if b > haveSight[-1]:
haveSight[-1] = b
else:
haveSight.append(b)
return haveSight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment