Maximum Points in a Perimeter-Bounded Rectangle
Updated
Problem statement
You are given a list of points in the plane with integer coordinates. No two points are the same. You are also given a non-negative integer perimeter.
Place one axis-aligned rectangle, meaning its sides are parallel to the x-axis and y-axis. Its width and height can be any non-negative real numbers, and its perimeter must be at most perimeter. A point is covered if it lies inside the rectangle or on its border.
Return the largest number of points that one such rectangle can cover.
Function
maxPointsWithPerimeter(points: int[][], perimeter: int) → intExamples
Example 1
points = [[0,0],[1,1],[2,2],[3,3]]perimeter = 8return = 3A rectangle from (0,0) to (2,2) has perimeter 8 and covers three points. To cover all four, it would need to be 3 wide and just as tall, so its perimeter would be 12. That is too much.
Example 2
points = [[0,0],[0,2],[2,0],[2,2],[10,10]]perimeter = 8return = 4The rectangle with corners (0,0) and (2,2) uses the whole allowed perimeter. It covers the four nearby points but not the far one.
Example 3
points = [[-3,1],[-1,1],[1,1],[3,1]]perimeter = 6return = 2All points lie on one line, so use a flat rectangle with zero height. Its width can be at most 3. That is enough to cover two points next to each other, but not three, so at most two points fit.
Constraints
1 <= points.length <= 200.points[i].length = 2.-10^9 <= points[i][0], points[i][1] <= 10^9.- All points are distinct.
0 <= perimeter <= 2 * 10^9.- A rectangle may have zero width or zero height.
More American Express interview questions
- Minimum Moves to Spread Stones Across a GridOA · Seen Sep 2026
- Largest Two Non-Overlapping Buildable SquaresOA · Seen Aug 2026
- Maximum Sum of Two Sign-Flipping WindowsOA · Seen Aug 2026
- Crop Text at a Whole-Word BoundaryOA · Seen Aug 2026
- Minimum Parking Roof LengthOA · Seen Aug 2026
- Minimum Pile Reduction StepsOA · Seen Aug 2026
- Disjoint Target-Sum TripletsPHONE SCREEN · Seen Mar 2025
Similar questions at other companies
- Best Meeting PointWalmart · OAWalmart interview questions
- Minimum Euclidean Distance Between PointsLuma AI · OALuma AI interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Meandering ArrayVerisk · OA
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
- Count Perfect PairsAdyen · OAAdyen interview questions
- HTTP Request RedirectionAmazon · OA