Find the Missing Number
You are given an unsorted array of integers as an argument. When sorted, the numbers in the array will form a sequence. One number in the sequence is missing. Return the missing number.
Requirements
- Must return a single integer.
- Number returned must be between the 0th and Kth index of the given array when sorted.
- Must also work with negative integers
Example 1
solve([5, 0, 2, 1, 3])
> 4
Sorted, the array will be 0,1,2,3,5, The missing number in this sequence is 4
Example 2
solve([-5, 0, -2, -1, -3])
> 4
Sorted, the array will be -5, -3, -2, -1, 0, The missing number in this sequence is -4