First Bad Version
Explore how to use modified binary search to find the first bad version in a sequence of software releases. Understand the problem constraints and implement an optimized solution by minimizing calls to the isBadVersion API. This lesson helps you develop skills in applying binary search in real-world coding interview questions.
We'll cover the following...
Statement
You are managing a product development team, and the latest release has failed quality checks. Because each version is built on top of the previous one, once a version is bad, every version after it is also bad.
You are given an array of n versions
You have access to an API isBadVersion(version) that returns TRUE if a given version is bad.
Your task is to find the first bad version while minimizing the number of calls to this API.
Constraints:
badn
Examples
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
Given n = , if version is the first bad version, how many API calls are required to find it?
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
Implement your solution in the following coding playground.
/* The this.isBadVersion(version) API is already defined for youwhich returns TRUE if a current version is bad. */import BadVersion from './BadVersion.js';class Solution extends BadVersion {constructor(bad) { super(bad); }firstBadVersion(n) {// Replace this placeholder return statement with your codereturn 0;}}export default Solution;