Easy · Binary Search

Binary search (recursive)

Given an array of distinct integers sorted in ascending order and a target value, return the index of the target using a recursive search, or -1 if it is not in the array.

Examples

Example 1

{
  "values": [1, 3, 4, 6, 8, 9, 11, 14, 17],
  "target": 9
}

Output: 5

Example 2

{
  "values": [1, 3, 4, 6, 8, 9, 11, 14, 17],
  "target": 7
}

Output: -1

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Binary Search problems