Skip to content

Instantly share code, notes, and snippets.

@wheatdog
Last active April 12, 2019 10:21
Show Gist options
  • Select an option

  • Save wheatdog/82a5a16ef2045c4cf3ba8ecfb5f2b03d to your computer and use it in GitHub Desktop.

Select an option

Save wheatdog/82a5a16ef2045c4cf3ba8ecfb5f2b03d to your computer and use it in GitHub Desktop.
def is_at_most_one_fixable_non_decreasing(num_list):
for skip_index in range(len(num_list)):
non_decreasing = True
for idx in range(1,len(num_list)):
if non_decreasing == False:
break
if idx == skip_idx:
continue
prev_idx = idx - 1
if prev_idx == skip_idx:
prev_idx -= 1
if prev_idx < 0:
continue
if num_list[prev_idx] > num_list[idx]:
non_decreasing = False
if non_decreasing == True:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment