Timer is Running

Find k-th missing element
Submissions: 3476   Accuracy:


  Difficulty: Easy   Marks: 2

Given two sequences, one is increasing sequence a[] and another a normal sequence b[], find the K-th missing element in the increasing sequence which is not present in the given sequence. If no K-th missing element is there output -1

Input:  a[] = {0, 2, 4, 6, 8, 10, 12, 14, 15};
        b[] = {4, 10, 6, 8, 12};
          k = 3
Output: 14
Explanation : The numbers from increasing sequence that
are not present in the given sequence are 0, 2, 14, 15.
The 3rd missing number is 14.

The first line consists of an integer T i.e number of test cases. The first line of each test case consists of three integers n1, n2 and k.The next line consists of n1 spaced integers. The next line consists of n2 spaced integers.

Print the kth number that is present in 1st array but not in 2nd.



9 5 3
0 2 4 6 8 10 12 14 15
4 10 6 8 12


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

Contributor: Saksham Ashtputre
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.