Search⌘ K
AI Features

Solution: Binary Search

Understand how to apply binary search to locate a target in a sorted array by splitting the search space repeatedly. This lesson guides you through an iterative approach, explains the algorithm's time and space efficiency, and helps you master one of the fundamental coding interview patterns.

Statement

We are given an array of integers, nums, sorted in ascending order, and an integer value, target. If the target exists in the array, return its index. If the target does not exist, return -1.

Constraints:

  • ...