 K-th missing element
Submissions: 7410   Accuracy: 26.41%   Difficulty: Easy   Marks: 2

Given an increasing sequence a[], we need to find the K-th missing contiguous element in the increasing sequence which is not present in the sequence. If no k-th missing element is there output -1.

Input:
The first line consists of an integer T i.e. the number of test cases. The first line of each test case consists of two integers N and K.Next line consists of N spaced integers.

Output:
For each test case, print the Kth missing number if present otherwise print -1.

Constraints:
1<=T<=100
1<=N,K,A[i]<=105

Examples:
Input

2
5 2
1 3 4 5 7
6 2
1 2 3 4 5 6
Output
6
-1

Explanation:
#TestCase 1:

K=2
We need to find the 2nd missing number in the array. Missing numbers are 2 and 6. So 2nd missing number is 6.
#Testcase 2:
K=2
We need to find the 2nd missing number in the array. As there is no missing number, hence the output is -1.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham_A
Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.