|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-points-inside-the-square">Maximum Points Inside the Square</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>You are given a 2D<strong> </strong>array <code>points</code> and a string <code>s</code> where, <code>points[i]</code> represents the coordinates of point <code>i</code>, and <code>s[i]</code> represents the <strong>tag</strong> of point <code>i</code>.</p> |
| 2 | + |
| 3 | +<p>A <strong>valid</strong> square is a square centered at the origin <code>(0, 0)</code>, has edges parallel to the axes, and <strong>does not</strong> contain two points with the same tag.</p> |
| 4 | + |
| 5 | +<p>Return the <strong>maximum</strong> number of points contained in a <strong>valid</strong> square.</p> |
| 6 | + |
| 7 | +<p>Note:</p> |
| 8 | + |
| 9 | +<ul> |
| 10 | + <li>A point is considered to be inside the square if it lies on or within the square's boundaries.</li> |
| 11 | + <li>The side length of the square can be zero.</li> |
| 12 | +</ul> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc1.png" style="width: 303px; height: 303px;" /></p> |
| 18 | + |
| 19 | +<div class="example-block"> |
| 20 | +<p><strong>Input:</strong> <span class="example-io">points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca"</span></p> |
| 21 | + |
| 22 | +<p><strong>Output:</strong> <span class="example-io">2</span></p> |
| 23 | + |
| 24 | +<p><strong>Explanation:</strong></p> |
| 25 | + |
| 26 | +<p>The square of side length 4 covers two points <code>points[0]</code> and <code>points[1]</code>.</p> |
| 27 | +</div> |
| 28 | + |
| 29 | +<p><strong class="example">Example 2:</strong></p> |
| 30 | + |
| 31 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc2.png" style="width: 302px; height: 302px;" /></p> |
| 32 | + |
| 33 | +<div class="example-block"> |
| 34 | +<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-2,-2],[-2,2]], s = "abb"</span></p> |
| 35 | + |
| 36 | +<p><strong>Output:</strong> <span class="example-io">1</span></p> |
| 37 | + |
| 38 | +<p><strong>Explanation:</strong></p> |
| 39 | + |
| 40 | +<p>The square of side length 2 covers one point, which is <code>points[0]</code>.</p> |
| 41 | +</div> |
| 42 | + |
| 43 | +<p><strong class="example">Example 3:</strong></p> |
| 44 | + |
| 45 | +<div class="example-block"> |
| 46 | +<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-1,-1],[2,-2]], s = "ccd"</span></p> |
| 47 | + |
| 48 | +<p><strong>Output:</strong> <span class="example-io">0</span></p> |
| 49 | + |
| 50 | +<p><strong>Explanation:</strong></p> |
| 51 | + |
| 52 | +<p>It's impossible to make any valid squares centered at the origin such that it covers only one point among <code>points[0]</code> and <code>points[1]</code>.</p> |
| 53 | +</div> |
| 54 | + |
| 55 | +<p> </p> |
| 56 | +<p><strong>Constraints:</strong></p> |
| 57 | + |
| 58 | +<ul> |
| 59 | + <li><code>1 <= s.length, points.length <= 10<sup>5</sup></code></li> |
| 60 | + <li><code>points[i].length == 2</code></li> |
| 61 | + <li><code>-10<sup>9</sup> <= points[i][0], points[i][1] <= 10<sup>9</sup></code></li> |
| 62 | + <li><code>s.length == points.length</code></li> |
| 63 | + <li><code>points</code> consists of distinct coordinates.</li> |
| 64 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 65 | +</ul> |
0 commit comments