Created
June 9, 2018 22:14
-
-
Save Rahul-Sagore/912ee2be14f6c6eafe17db8511b7cffd 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
// Find missing number in sorted array | |
//[1, 2, 3, 6] => 5 | |
function findMissingNumber(arr){ | |
var len = arr.length; | |
var totalSum = (len * (len + 1))/2 | |
return totalSum - arr.reduce((acc, curr) => acc + curr, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment