Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created February 22, 2021 21:15
Show Gist options
  • Select an option

  • Save mvallebr/6fdc3ba92c6c2c7b07c646f6c08d496e to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/6fdc3ba92c6c2c7b07c646f6c08d496e to your computer and use it in GitHub Desktop.
def get_skyline(buildings):
result = []
xs = sorted([x for x1, x2, _ in buildings for x in (x1, x2)])
last_y = None
for x in xs:
y = max((y for x1, x2, y in buildings if x1 <= x < x2), default = 0)
if y != last_y:
result.append([x, y])
last_y = y
return result
if __name__ == '__main__':
n = int(input())
buildings = [[int(x) for x in input().split()] for _ in range(n)]
print(get_skyline(buildings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment