Skip to content

Instantly share code, notes, and snippets.

@no1xsyzy
Last active August 30, 2019 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no1xsyzy/8b6722db07b769494f52568c0a9d8154 to your computer and use it in GitHub Desktop.
Save no1xsyzy/8b6722db07b769494f52568c0a9d8154 to your computer and use it in GitHub Desktop.
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