2
def binarySearch(self, arr, target):3
left, right = 0, len(arr)6
mid = left + ((right - left) // 2)8
# Potential answer found! Now try to minimize it iff possible.16
self, rectangles: List[List[int]], points: List[List[int]]18
# Sort rectangles based on the lengths20
# Group rectangles by their height in increasing order of their length22
for x, y in rectangles:28
heights = sorted(list(lengths.keys()))30
count = [0] * len(points)32
for idx, point in enumerate(points):34
# Get the min height rectangle that would accommodate the y coordinate of current point.35
minHeightRectIdx = self.binarySearch(heights, y)36
if minHeightRectIdx is not None:37
for h in heights[minHeightRectIdx:]:38
# Get the Min length rectangle that would accommodate the x coordinate of current point for all h height rectangles.39
minLenRectIdx = self.binarySearch(lengths[h], x)40
if minLenRectIdx is not None:41
count[idx] += len(lengths[h]) - minLenRectIdx