|
| 1 | +<p>You are given a 2D integer array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, h<sub>i</sub>]</code> indicates that <code>i<sup>th</sup></code> rectangle has a length of <code>l<sub>i</sub></code> and a height of <code>h<sub>i</sub></code>. You are also given a 2D integer array <code>points</code> where <code>points[j] = [x<sub>j</sub>, y<sub>j</sub>]</code> is a point with coordinates <code>(x<sub>j</sub>, y<sub>j</sub>)</code>.</p> |
| 2 | + |
| 3 | +<p>The <code>i<sup>th</sup></code> rectangle has its <strong>bottom-left corner</strong> point at the coordinates <code>(0, 0)</code> and its <strong>top-right corner</strong> point at <code>(l<sub>i</sub>, h<sub>i</sub>)</code>.</p> |
| 4 | + |
| 5 | +<p>Return<em> an integer array </em><code>count</code><em> of length </em><code>points.length</code><em> where </em><code>count[j]</code><em> is the number of rectangles that <strong>contain</strong> the </em><code>j<sup>th</sup></code><em> point.</em></p> |
| 6 | + |
| 7 | +<p>The <code>i<sup>th</sup></code> rectangle <strong>contains</strong> the <code>j<sup>th</sup></code> point if <code>0 <= x<sub>j</sub> <= l<sub>i</sub></code> and <code>0 <= y<sub>j</sub> <= h<sub>i</sub></code>. Note that points that lie on the <strong>edges</strong> of a rectangle are also considered to be contained by that rectangle.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong>Example 1:</strong></p> |
| 11 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example1.png" style="width: 300px; height: 509px;" /> |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]] |
| 14 | +<strong>Output:</strong> [2,1] |
| 15 | +<strong>Explanation:</strong> |
| 16 | +The first rectangle contains no points. |
| 17 | +The second rectangle contains only the point (2, 1). |
| 18 | +The third rectangle contains the points (2, 1) and (1, 4). |
| 19 | +The number of rectangles that contain the point (2, 1) is 2. |
| 20 | +The number of rectangles that contain the point (1, 4) is 1. |
| 21 | +Therefore, we return [2, 1]. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong>Example 2:</strong></p> |
| 25 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example2.png" style="width: 300px; height: 312px;" /> |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]] |
| 28 | +<strong>Output:</strong> [1,3] |
| 29 | +<strong>Explanation: |
| 30 | +</strong>The first rectangle contains only the point (1, 1). |
| 31 | +The second rectangle contains only the point (1, 1). |
| 32 | +The third rectangle contains the points (1, 3) and (1, 1). |
| 33 | +The number of rectangles that contain the point (1, 3) is 1. |
| 34 | +The number of rectangles that contain the point (1, 1) is 3. |
| 35 | +Therefore, we return [1, 3]. |
| 36 | +</pre> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<ul> |
| 42 | + <li><code>1 <= rectangles.length, points.length <= 5 * 10<sup>4</sup></code></li> |
| 43 | + <li><code>rectangles[i].length == points[j].length == 2</code></li> |
| 44 | + <li><code>1 <= l<sub>i</sub>, x<sub>j</sub> <= 10<sup>9</sup></code></li> |
| 45 | + <li><code>1 <= h<sub>i</sub>, y<sub>j</sub> <= 100</code></li> |
| 46 | + <li>All the <code>rectangles</code> are <strong>unique</strong>.</li> |
| 47 | + <li>All the <code>points</code> are <strong>unique</strong>.</li> |
| 48 | +</ul> |
0 commit comments