Skip to content

Instantly share code, notes, and snippets.

@burakozturk16
Created October 16, 2021 09:24
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 burakozturk16/817a7d7a6eeae15eff8651dc950d6ef5 to your computer and use it in GitHub Desktop.
Save burakozturk16/817a7d7a6eeae15eff8651dc950d6ef5 to your computer and use it in GitHub Desktop.
def main(nums):
numCount = len(nums) # 4
arr = list(nums) # [3, 1, 4, 2]
for i in range(1,numCount):
arr[i] = min(nums[i-1], arr[i-1])
j = numCount
for i in range(numCount)[::-1]:
if nums[i] <= arr[i]:
continue
while j < numCount and arr[j] <= arr[i]:
j += 1
if j < numCount and arr[j] < nums[i]:
return True
if nums[i] > arr[i - 1]:
j -= 1
arr[j] = nums[i]
return False
# -- main ----
nums = "-1 3 2 0".split()
print("PASS" if main(nums) else "FAIL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment