Description

Find the first bad version given n versions where isBad(version) returns true for bad versions. Return the array [firstBadVersion].

Examples

Input:n = 5, bad = 4
Output:4
Explanation:

Versions 4 and 5 are bad, first is 4.

Input:n = 3, bad = 1
Output:1
Explanation:

All versions 1, 2, and 3 are bad since bad versions are consecutive from the first bad one. The first bad version is 1.

Input:n = 8, bad = 8
Output:8
Explanation:

Only the last version (version 8) is bad. Versions 1 through 7 are good, so the first and only bad version is 8.

Constraints

  • 1 ≤ n ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!