Maximum-Area Rectangle from Points
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole problem hinges on a hash set, and Google's September 2026 OA makes you earn it. You get up to 500 distinct points and have to find the biggest rectangle, tilted ones included. Brute force over four points is dead on arrival. If you're taking this in the next day or two, know the trick before you open the editor. It's a geometry problem wearing a hash-table costume. StealthCoder is the safety net if your mind goes blank mid-assessment, but the idea below is short enough to memorize tonight.
The problem
Given distinct integer-coordinate points in the plane, choose four of them that form a rectangle. The rectangle's sides do not need to be parallel to the axes. Return the maximum possible rectangle area. Return 0 when no rectangle can be formed. Function maximumRectangleArea(points: int[][]) → long Examples Example 1 points = [[1,2],[2,1],[1,0],[0,1]] return = 2 The four points form a rotated square of area 2. Example 2 points = [[0,0],[0,2],[3,0],[3,2],[1,1]] return = 6 The axis-aligned rectangle with width 3 and height 2 is largest. Example 3 points = [[0,0],[1,1],[2,3]] return = 0 No four points are available to form a rectangle. Constraints 1 <= points.length <= 500. Every point contains exactly two integers in [-40000, 40000]. All points are distinct. The answer fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Pick three points A, B, C and check whether AB is perpendicular to BC (dot product zero). If so, the fourth point is D = A + C - B. Look D up in a hash set of encoded points. That's O(n^3) with 500 points, about 20 million checks after pruning, which is fine. A faster route: group pairs of points by diagonal midpoint and squared length. Two diagonals sharing the same midpoint and length form a rectangle. Bucket pairs in a hash map, then for each bucket compute areas from the pairs. Pitfalls: use long for area and cross products, encode points as x*100003+y or use a tuple key, and don't double count or divide by zero. Area is |AB| times |BC| via the cross product magnitude, so you never need square roots. If you freeze during the live OA, StealthCoder can hand you the midpoint-bucket version fast.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Maximum-Area Rectangle from Points cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum area rectangle ii. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum-Area Rectangle from Points FAQ
How hard is Maximum-Area Rectangle from Points really?+
Medium to hard. The idea is simple once you see it, but tilted rectangles throw people who only know the axis-aligned version. With 500 points, an O(n^3) approach with a hash set lookup passes, so you don't need anything exotic.
What's the trick for the Google September 2026 version?+
Use a perpendicularity check or diagonal grouping. For three points with a right angle at B, the fourth is A + C - B. Check it in a hash set. Alternatively, bucket point pairs by midpoint and squared distance, since matching diagonals always make a rectangle.
Do I need floating point math?+
No. Everything stays integer. Use dot products to test right angles and the cross product magnitude for area. Skip square roots entirely. Use 64-bit longs because coordinates reach 40000 and products get large quickly.
How do I handle the no-rectangle case?+
Start your best answer at 0 and only update it when you find a valid fourth point. Example 3 has fewer than four points, so the loops find nothing and you return 0. No special casing needed beyond that.
How do I prep for this in 48 hours?+
Practice the point-encoding hash set and the vector math once. Write the O(n^3) version, then the midpoint-bucket version. Test on the rotated square from Example 1. Watch for overflow and duplicate counting. That's enough for this pattern.