Reported September 2026
Metabinary search

First Bad Version in a Monotone Array

Reported by candidates from Meta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Meta OA. Under 2s to a working solution.
Founder's read

Meta reportedly put this one in front of candidates in September 2026, and the input size is the whole story. With up to 10^6 versions, a linear scan isn't what the question is testing for. The array is monotone, false then true, so you're finding a boundary, not searching for a value. That's binary search on a boolean array, plus one edge case for the all-good input. It looks like a warmup, and that's why people lose points on it: off-by-one errors and the -1 return. If you blank on the loop invariants during the live OA, StealthCoder is the safety net running invisibly on your screen.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that monotone means you can discard half the array every step. Keep lo = 0 and hi = n. While lo < hi, compute mid = lo + (hi - lo) / 2. If bad[mid] is true, the answer is at mid or earlier, so set hi = mid. Otherwise set lo = mid + 1. When the loop ends, lo is the first true index, or n if none exists. Return -1 when lo equals n. The common pitfall is using hi = n - 1 with a mismatched loop condition, which skips the last element or loops forever. Another is returning mid the moment you see true, which isn't necessarily the first one. This runs in O(log n) time and O(1) space. If the loop bounds slip under pressure, StealthCoder is the hedge during the live OA, since it reads the problem and hands you a clean solution.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill First Bad Version in a Monotone Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Meta's OA.

Meta reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

First Bad Version in a Monotone Array FAQ

How hard is First Bad Version really?+

Easy on paper. The algorithm is a textbook lower-bound binary search. Where people fail is boundary handling, specifically the all-false case that returns -1 and the all-true case that returns 0. Write those two tests by hand before you submit.

What's the trick to solving it fast?+

Treat it as finding the leftmost true. Use a half-open range [lo, hi) with hi = n. If bad[mid] is true, set hi = mid. Otherwise set lo = mid + 1. After the loop, check whether lo equals n and return -1 if so.

Why not just scan linearly?+

A scan is O(n) and technically works at 10^6, but the monotone guarantee is a clear hint that binary search is expected. Meta-style graders often care about the approach, so a linear answer risks being marked down even when it passes.

Which edge cases should I test?+

Test a single-element array that's true, a single-element array that's false, and an all-false array that returns -1. Also test an all-true array that returns 0, and a case where the boundary sits at the last index. Those cover nearly every off-by-one bug.

How do I prepare for this in 48 hours?+

Write the lower-bound binary search template from memory three times until the lo, hi, and mid updates feel automatic. Then do a few variants, like first element greater than or equal to a target. The same invariant covers all of them.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Meta.

OA at Meta?
Invisible during screen share
Get it