Skip to content

Instantly share code, notes, and snippets.

@dashohoxha
Created April 11, 2018 12:03
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 dashohoxha/064d1a68703192fa0c110934c942747e to your computer and use it in GitHub Desktop.
Save dashohoxha/064d1a68703192fa0c110934c942747e to your computer and use it in GitHub Desktop.
def troublesort(V):
done = False
while not done:
done = True
for i in range(len(V)-2):
if V[i] > V[i+2]:
done = False
V[i], V[i+2] = V[i+2], V[i]
def check(V):
for i in range(len(V)-1):
if V[i] > V[i+1]:
return i
return 'OK'
T = int(input())
for t in range(T):
N = int(input())
V = list(map(int, input().split()))
troublesort(V)
print("Case #{}: {}".format(t+1, check(V)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment