FastPrepFirst Bad Version in a Monotone Array
Problems/First Bad Version in a Monotone Array

First Bad Version in a Monotone Array

Meta logoMeta● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report identifies a hand-written binary-search problem comparable to the familiar first-bad-version task. The Boolean-array adapter replaces the unavailable external predicate and matches the recognizable exercise at about 87%.

The Boolean array bad describes software versions in chronological order. Once a version is bad, every later version is also bad.

Return the zero-based index of the first bad version, or -1 when every version is good.

Function

firstBadVersion(bad: boolean[]) → int

Examples

Example 1

bad = [false,false,true,true]return = 2

Index 2 is the first true entry.

Example 2

bad = [true,true]return = 0

The first version is already bad.

Example 3

bad = [false,false]return = -1

No bad version exists.

Constraints

  • 1 <= bad.length <= 10^6.
  • The array is monotone: no false appears after a true.

More Meta problems

  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int firstBadVersion(boolean[] bad) {
        // Write your solution here.
    }
}
Checking account…