Skip to the code
cf.
+10 XP

#150 Locate a Build Number

easy

Your team's deploy dashboard keeps every build number it has shipped in builds, sorted from smallest to largest, with no repeats.

Write findBuild(builds, target) that returns the index of target in builds, or -1 if that build was never shipped.

The dashboard can hold hundreds of thousands of builds, so check as few of them as you can: aim for O(log n).

Example 1

Input: builds = [101,104,107,115,120,133], target = 115
Output: 3

115 sits at index 3.

Example 2

Input: builds = [101,104,107,115,120,133], target = 110
Output: -1

110 was never shipped.

Constraints

  • 0 <= builds.length <= 100000
  • builds is sorted ascending and has no duplicates.
  • -10^9 <= builds[i], target <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).