Feature #9: Kth Missing Gene
Explore how to identify the kth missing gene in a sorted DNA sequence. Understand how to leverage binary search by calculating missing genes before an index to efficiently solve this computational biology problem with optimal time and space complexity.
We'll cover the following...
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, gene_A, we want to find the missing gene in a sorted order. The given DNA sequence will be sorted in strictly increasing order.
Constraints
1 <= gene_A[i] <= 10001<= k <= 1000gene_A[i] <= gene_A[j] for 1 <= i < j <= gene_A.length
The following examples may clarify this problem:
Solution
Our input is sorted in 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 gene_A in order to use the binary search algorithm. To find the number of missing genes, we will compare our input array, gene_A, with an array that has no missing genes.
Suppose that the input array, ...