Last active
May 18, 2020 06:47
-
-
Save remi-bruguier/093757e835e18670888b36988e6371b6 to your computer and use it in GitHub Desktop.
You are given an array of integers in an arbitrary order. Return whether or not it is possible to make the array non-decreasing by modifying at most 1 element to any value.
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
const couldBeMadeNonDecreasing = (arr:number[]):Boolean => { | |
let decreasingPairs = 0 | |
for(let i in arr){ | |
if(arr[i] > arr[+i+1]){ | |
decreasingPairs++ | |
} | |
} | |
return decreasingPairs <= 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment