Created
February 22, 2021 21:15
-
-
Save mvallebr/6fdc3ba92c6c2c7b07c646f6c08d496e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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