Last active
August 30, 2019 01:50
-
-
Save no1xsyzy/8b6722db07b769494f52568c0a9d8154 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
def deleteorder(x): | |
n = len(x) | |
if n%2 != 0: | |
return | |
if any(x.count(i) > n//2 for i in set(x)): | |
return | |
x = sorted(x) | |
assert all(x[i] < x[i + n//2] for i in range(n//2)) | |
# since x[0] <= x[1] <= x[2] <= ... <= x[n-1] | |
# there must be x[i] <= x[i + n//2] | |
# suppose if x[i] == x[i + n//2] | |
# then x[i] == x[i+1] == x[i+2] == ... == x[i + n//2] | |
# then x.count(x[i]) >= n//2 + 1 > n//2 | |
# which is impossible via L5 | |
return list(zip(x[:n//2], x[n//2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment