Feature #9: Kth Missing Gene

Implement the "Kth Missing Gene" feature for our "Computational Biology" project.

Description

A planet has n genes, numbered 1 to n. Every species on the planet has a subset of these genes in its DNA sequence. For a given species’ DNA, A, we want to find the kthk^{th} missing gene in a sorted order. The given DNA sequence will be sorted in strictly increasing order.

The following examples may clarify this problem:

Solution

Our input is sorted in an ascending order. We can use this fact and try to solve this problem using binary search. However, we need to find the number of missing genes that come before a given gene in the DNA arr in order to use the binary search algorithm. To find the number of missing genes, we will compare our input array, arr, with an array that has no missing genes.

Suppose that the input array, arr, is [2, 3, 4, 7, 11]. We will compare it to an array with no missing genes, ...

Access this course and 1400+ top-rated courses and projects.