Search⌘ K
AI Features

Solution: Binary Search

Understand how to apply the binary search algorithm to efficiently locate a target value in a sorted array. Learn the step-by-step iterative approach that repeatedly halves the search space based on comparisons with the middle element. This lesson equips you with skills to solve search problems with logarithmic time and constant space complexity, essential for coding interviews.

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:

  • ...