Description

Bisect range utilizes Bisect Left-Right by finding the left and right indexes to get the range or size of range
?

Reach for when

You want to get all items within a range (min, max) in a sorted array.

Runtime

O(log(n))

Visualization

Bisect Range-1783985963381.webp683

Pseudocode

left_index = bisect_left(arr, min_value)
right_index = bisect_right(arr, max_value)-1 # -1 for inclusive
range is arr[left_index:right_index]

Code

def get_range(min, max):
	left = bisect_left(arr, min)
	right = bisect_right(arr, max)-1 # -1 for inclusive
	return arr[left:right]