Last active
June 8, 2020 13:57
-
-
Save mwshubham/aa7ee6cf5a1f79ecafaf733129ccd537 to your computer and use it in GitHub Desktop.
This file contains 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
result = [] | |
n = int(input()) | |
arr = list(map(int, input().split())) | |
for i in range(0,2*n, 2): | |
result.append([arr[i],arr[i+1]]) | |
# sort a array based on first element | |
result.sort(key=lambda x: x[0]) | |
j = 0 | |
while j < len(result)-1: | |
if result[j][1] >= result[j+1][0]: | |
if result[j][1] <= result[j+1][1]: | |
result[j][1] = result[j+1][1] | |
del result[j+1] | |
else: | |
j = j + 1 | |
for i in range(len(result)): | |
print(result[i][0], result[i][1], end =" ") | |
print() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment