Leetcode Problem 2250. Count Number of Rectangles Containing Each Point

2250. Count Number of Rectangles Containing Each Point

Leetcode Solutions

Binary Search on Sorted Rectangle Lengths

  1. Initialize an array heightToLengths to store lists of lengths indexed by their heights.
  2. Iterate over each rectangle and add its length to the list corresponding to its height in heightToLengths.
  3. Sort each list of lengths in heightToLengths.
  4. Initialize an array counts to store the result for each point.
  5. For each point, do the following: a. Initialize a counter count to 0. b. Iterate over each height starting from the point's y-coordinate up to 100. c. If there are lengths for the current height, perform binary search to find the number of lengths greater than or equal to the point's x-coordinate. d. Add the result of the binary search to count.
  6. Store count in the counts array for the current point.
  7. Return the counts array.
UML Thumbnail

Brute Force Check for Each Point

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...