First Bad Version
Try to solve the First Bad Version problem.
We'll cover the following
Statement#
The latest version of a software product fails the quality check. Since each version is developed upon the previous one, all the versions created after a bad version are also considered bad.
Suppose you have n versions with the IDs , and you have access to an API function that returns TRUE if the argument is the ID of a bad version.
Find the first bad version that is causing all the later ones to be bad. Additionally, the solution should also return the number of API calls made during the process and should minimize the number of API calls too.
Constraints:
- first bad version
n
Examples#
1 of 3
2 of 3
3 of 3
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
First Bad Version
What is the output if n = 10 and the first bad version is 6?
6, 5
6, 4
6, 3
6, 2
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Note: For each test case, the “Expected Output” column in the “Show Results” tab below will list the first bad version as well as the maximum number of calls to the API function that the correct solution will make.
Implement your solution in the following coding playground:
Modified Binary Search: Introduction
Solution: First Bad Version