P5 · 1 second · 256 MB
First True
You are given a monotone boolean array `ok` that is zero or more `false` values followed by zero or more `true` values. Return the first index where `ok[i]` is true. If there is no true, return `ok.length`. Do this in logarithmic probes — a linear scan will be too slow in spirit even if JS can brute the MVP sizes. Implement `firstTrue(ok)`.
function firstTrue(ok) → number
CONSTRAINTS
- 1 ≤ ok.length ≤ 10⁴
- ok[i] is boolean
- There is at most one cut from false to true
Input: ok = [false, false, true, true]
Output: 2
Input: ok = [true, true]
Output: 0
Input: ok = [false, false]
Output: 2
1
2
3
4
5
6
7
8
Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.