Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_sorted(array):
- for i in range(1, len(array)):
- # Check if element is not sorted
- if array[i] < array[i - 1]:
- return False
- return True
- def solve(array):
- changed = True
- while changed:
- changed = False
- if is_sorted(array):
- return "YES"
- for i in range(1, len(array) - 1):
- if array[i - 1] < array[i] > array[i + 1]:
- array[i], array[i + 1] = array[i + 1], array[i]
- changed = True
- return "NO"
- def main():
- number_of_sets = int(input())
- for i in range(number_of_sets):
- number_of_ints = int(input()) # NOT USED
- given_array = input()
- given_array = list(map(int, given_array.split()))
- print(solve(given_array))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement