First Bad Version
Updated
Problem statement
A product has versions numbered from 1 through n. Once a version is bad, every later version is also bad.
You are given a boolean array isBad of length n, where isBad[i] reports whether version i + 1 is bad. At least one version is bad.
Return the number of the first bad version.
Function
firstBadVersion(isBad: boolean[]) → intExamples
Example 1
isBad = [false,false,false,true,true]return = 4Versions 1 through 3 are good, and version 4 is the first bad version.
Example 2
isBad = [true]return = 1The only version is bad, so it is also the first bad version.
Example 3
isBad = [false,true,true,true]return = 2Version 1 is good, while version 2 and every later version are bad.
More Qualcomm Phone Screen questions
Similar questions at other companies
- First Element Greater Than KMeta · PHONE SCREENMeta interview questions
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
- First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
- Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
- Lowest Common Ancestor in an Inserted BSTAmazon · PHONE SCREEN
- Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
- Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions