Given 'VEC' : {1,4,5,7}
'K' : 3
As shown in the above figure, numbers 2, 3, and 6 are missing. Since 6 is the third missing element, it is the required answer.
The first line contains an integer ‘N’ denoting the number of elements in the array/list.
The second line contains ‘N’ space-separated integers denoting the elements of the array/list.
The third line contains an integer ‘K’ denoting the 'Kth' missing element.
Print the 'Kth' missing contiguous element in the given sequence.
You don't need to print anything, it has already been taken care of. Just implement the given function.
Try to solve it in O(log(N)).
1 <= N <= 10^4
1 <= K <= 10^9
-10^9 <= VEC[i] <= 10^9
Time Limit : 1 sec
4 4 7 9 10 1
For each element check whether the current and next element is consecutive or not. If not, take the difference between the two and check till the difference is greater or equal to the given value of ‘K’. If the difference is greater, return current element - ’COUNT’.
Here is the algorithm :
At any index, we can check how many elements are missing till the element at that index. Now, using binary search we’ll find the closest index to the required answer.
Here is the algorithm :
Merge Two Sorted Arrays Without Extra Space
Search In A Sorted 2D Matrix
Ninja And The Strictly Increasing Array
Negative To The End
Fake Coin Problem