You are viewing a single comment's thread. Return to all comments →
using deque with python
from collections import deque one = False two = False for target in range(min(arr),max(arr)+1): while target != arr[0]: position = arr.index(target) if position-2 >= 0: chunk = arr[position-2:position + 1] one = True elif len(arr) == 3: chunk = arr else: chunk = arr[:position + 2] two = True while chunk.index(target) != 0: if type(chunk) == list: chunk = deque(chunk) chunk.rotate(-1) if one: arr[position-2:position + 1] = list(chunk) one = False else: arr[:position + 2] = list(chunk) two = False arr = arr[1:] if len(arr) < 3 and arr != sorted(arr): return ('NO') elif arr == sorted(arr): return ('YES')
Seems like cookies are disabled on this browser, please enable them to open this website
Larry's Array
You are viewing a single comment's thread. Return to all comments →
using deque with python