Created
October 16, 2021 09:24
-
-
Save burakozturk16/817a7d7a6eeae15eff8651dc950d6ef5 to your computer and use it in GitHub Desktop.
This file contains 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
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