Skip to content

Instantly share code, notes, and snippets.

@thilinapiy
Created January 28, 2019 05:44
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 thilinapiy/4969cf70453fa8b30ddacebcb7cfc6d3 to your computer and use it in GitHub Desktop.
Save thilinapiy/4969cf70453fa8b30ddacebcb7cfc6d3 to your computer and use it in GitHub Desktop.
#!/bin/env python
# python3.6 filename
def solution(A):
out_of_order_count = 0
existing_hights = A
sorted_hights = sorted(A)
i = 0
j = 0
for tree in existing_hights:
if j < len(existing_hights):
print(existing_hights[i], sorted_hights[j])
if sorted_hights[i] == existing_hights[j]:
pass
else:
j = j + 1
out_of_order_count = out_of_order_count + 1
i = i + 1
j = j + 1
if out_of_order_count < 2:
print("OK")
return 0
else:
print("Nops")
print(out_of_order_count)
return out_of_order_count
solution([2,3,5,4])
solution([4,5,2,3,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment