Problem: kth Missing Element in a Sequence

Given a strictly increasing sequence of integers VEC, identify the Kth missing contiguous integer element that is not present in the sequence, starting from the leftmost element of the sequence.

Input:

The first line of input contains an integer 'T' denoting the number of test cases.

For each test case:
- The first line contains an integer 'N', denoting the number of elements in the array/list.
- The second line contains 'N' space-separated integers, representing the elements of the array/list.
- The third line contains an integer 'K', which specifies the Kth missing element to find.

Output:

For each test case, output the 'Kth' missing contiguous element from the given sequence.

Example:

Input:
VEC = {1, 4, 5, 7}
K = 3
Explanation:
Numbers 2, 3, and 6 are missing. Since 6 is the third missing element, it is the required answer.

Constraints:

  • 1 <= T <= 10^2
  • 1 <= N <= 10^4
  • 1 <= K <= 10^9
  • -10^9 <= VEC[i] <= 10^9

Note:

You do not need to print anything; it is already handled. Your task is to implement the required function.

Additional Challenge:

Attempt to solve the problem with a time complexity of O(log(N)).
Be the first one to answer
Add answer anonymously...
Athenahealth Technology Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter