Dsa
Binary Search
Warm-up
Find the First Bad Version
You are given a list of versions with a boolean indicator of whether they are good or bad, where a version is bad if it is the first instance or any version after it. Write a function that identifies the first bad version in the list. Each version's status is defined in a boolean array. If there are no bad versions, return -1.
Input Format:
- A single line containing space-separated boolean values (1 for bad, 0 for good).
Output Format:
- An integer representing the index of the first bad version or -1 if none exist.
Example:
Input:
0 0 0 1 1
Output:
3
Key concepts
binary_searcharraysearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now