Binary Search

Try to solve the Binary Search problem.

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:

  • 11≤\leq nums.length ≤\leq 10410^4

  • −104-10^4≤\leq nums[i] , target ≤\leq 10410^4

  • All integers in nums are unique.

  • nums is sorted in ascending order.

Example

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy