Leaderboard
Showing:
Find k-th missing element
Easy Accuracy: 11.11% Submissions: 9 Points: 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

 

Example 1:

Input : Arr[] = {0, 2, 4, 6, 8, 10, 12, 14, 15}
Brr[] = {4, 10, 6, 8, 12}
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.

Example 2:

Input : Arr[] = {1, 2, 3, 4, 5}
Brr[] = {5, 4, 3, 1, 2} and K = 3
Output : -1


Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function MissingNumber() that takes an array (a), another array (b), an element K, size of first array (n), size of the second array (m)and return the Kth missing number in an array a, if you can't find it return -1. The driver code takes care of the printing.

Expected Time Complexity: O(n + m).
Expected Auxiliary Space: O(m).

Constraints:
1 ≤ n,m,k ≤ 105
1 ≤ a[i] ≤ 108
1 ≤ b[i] ≤ 103

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Find k-th missing element

Output Window