Search⌘ K
AI Features

Solution: Binary Search

Explore how to apply binary search to locate a target in a sorted array by repeatedly dividing the search space. Learn the step-by-step iterative approach, understand its logarithmic time complexity, and the constant space requirements to implement this efficient searching technique.

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:

  • ...