Tap here to switch tabs
Problem
Submissions

Problem: Binary Searchable Numbers in an Unsorted Array

Try to solve the Binary Searchable Numbers in an Unsorted Array problem.

Statement

Consider a standard binary search algorithm applied to an array nums of unique integers to find a target value target. At each step, a pivot is chosen from the current search range. If the pivot value equals target, the algorithm successfully finds the target. If the pivot value is strictly greater than target, the search space narrows to the elements to the left of the pivot. If the pivot value is strictly smaller than target, the search space narrows to the elements to the right of the pivot.

An element target present in nums is called binary searchable if the binary search algorithm is guaranteed to find it, regardless of which pivot is chosen at each step.

Given an integer array nums, return the number of elements in nums that are binary searchable.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • All the values of nums are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Binary Searchable Numbers in an Unsorted Array

Try to solve the Binary Searchable Numbers in an Unsorted Array problem.

Statement

Consider a standard binary search algorithm applied to an array nums of unique integers to find a target value target. At each step, a pivot is chosen from the current search range. If the pivot value equals target, the algorithm successfully finds the target. If the pivot value is strictly greater than target, the search space narrows to the elements to the left of the pivot. If the pivot value is strictly smaller than target, the search space narrows to the elements to the right of the pivot.

An element target present in nums is called binary searchable if the binary search algorithm is guaranteed to find it, regardless of which pivot is chosen at each step.

Given an integer array nums, return the number of elements in nums that are binary searchable.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • All the values of nums are unique.