Binary Search

ItemValue
Data StructureArray
Worst-case Time ComplexityO(logn)
Best-case Time ComplexityO(1)
Average Time ComplexityO(logn)
Worst-case Space ComplexityO(1)

Unique Position

Find the index of x in nums, where all elements are unique.

Left Insertion Position

Locate the insertion point for x in nums to maintain sorted order. If x is already present in nums, the insertion point will be before (to the left of) any existing entries.

Right Insertion Position

Locate the insertion point for x in nums to maintain sorted order. If x is already present in nums, the insertion point will be after (to the right of) any existing entries.

Tests