3143. Maximum Points Inside the Square Medium
1/**
2 * [3143] Maximum Points Inside the Square
3 *
4 * You are given a 2D array points and a string s where, points[i] represents the coordinates of point i, and s[i] represents the tag of point i.
5 * A valid square is a square centered at the origin (0, 0), has edges parallel to the axes, and does not contain two points with the same tag.
6 * Return the maximum number of points contained in a valid square.
7 * Note:
8 *
9 * A point is considered to be inside the square if it lies on or within the square's boundaries.
10 * The side length of the square can be zero.
11 *
12 *
13 * <strong class="example">Example 1:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc1.png" style="width: 303px; height: 303px;" />
15 * <div class="example-block">
16 * Input: <span class="example-io">points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca"</span>
17 * Output: <span class="example-io">2</span>
18 * Explanation:
19 * The square of side length 4 covers two points points[0] and points[1].
20 * </div>
21 * <strong class="example">Example 2:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc2.png" style="width: 302px; height: 302px;" />
23 * <div class="example-block">
24 * Input: <span class="example-io">points = [[1,1],[-2,-2],[-2,2]], s = "abb"</span>
25 * Output: <span class="example-io">1</span>
26 * Explanation:
27 * The square of side length 2 covers one point, which is points[0].
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">points = [[1,1],[-1,-1],[2,-2]], s = "ccd"</span>
32 * Output: <span class="example-io">0</span>
33 * Explanation:
34 * It's impossible to make any valid squares centered at the origin such that it covers only one point among points[0] and points[1].
35 * </div>
36 *
37 * Constraints:
38 *
39 * 1 <= s.length, points.length <= 10^5
40 * points[i].length == 2
41 * -10^9 <= points[i][0], points[i][1] <= 10^9
42 * s.length == points.length
43 * points consists of distinct coordinates.
44 * s consists only of lowercase English letters.
45 *
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/maximum-points-inside-the-square/
50// discuss: https://leetcode.com/problems/maximum-points-inside-the-square/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55 pub fn max_points_inside_square(points: Vec<Vec<i32>>, s: String) -> i32 {
56 0
57 }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_3143() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.