Created
January 28, 2019 05:44
-
-
Save thilinapiy/4969cf70453fa8b30ddacebcb7cfc6d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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