Skip to content
QuizMaker logoQuizMaker
Activity
DSA Interview Patterns Roadmap

No lessons available

CONTENTS

Maximum Rectangle from Coordinates

Turn the Maximum Rectangle from Coordinates interview variant into a clear brute-force baseline, optimized pattern, and implementation plan.

DSA Interview Patterns Roadmap
Company Asked Variants
dsa
coding interview
+5
May 29, 2026
19
A

Learning Outcome

Turn the Maximum Rectangle from Coordinates interview variant into a clear brute-force baseline, optimized pattern, and implementation plan.

Original Interview Statement

Given points, find the maximum-area rectangle, including tilted rectangles.

Examples

ItemDetail
points forming a square of side 2area 4

Brute Force Approach

Check every quadruple and test rectangle properties.

Optimized Approach

Two diagonals of a rectangle share the same midpoint and length. Group point pairs by midpoint and squared length; combine pairs in each group.

Exact Pseudocode

for every pair of points:
  key = midpoint sum and dist2
  for previous pair with same key:
    area = abs(cross(p1-p3, p2-p3))
  add pair to group

Reference Code

from collections import defaultdict

def max_rectangle_area(points):
    groups = defaultdict(list)
    best = 0
    for i in range(len(points)):
        x1, y1 = points[i]
        for j in range(i + 1, len(points)):
            x2, y2 = points[j]
            key = (x1 + x2, y1 + y2, (x1 - x2) ** 2 + (y1 - y2) ** 2)
            for a, b in groups[key]:
                x3, y3 = points[a]
                x4, y4 = points[b]
                area2 = abs((x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3))
                best = max(best, area2)
            groups[key].append((i, j))
    return best

Complexity

ItemDetail
Brute forceO(n^4)
OptimizedO(n^2) pairs; group combinations depend on collisions

Edge Cases

  • Duplicate points
  • Axis-aligned rectangle
  • Tilted rectangle
  • Zero area

Follow-ups

  • Minimum area rectangle
  • Return coordinates

Nearest Practice References

  • Minimum Area Rectangle II
  • Valid Square

Common Mistakes

  • Copying the nearest LeetCode solution without checking the changed rule.
  • Skipping duplicate or boundary cases.
  • Not stating the brute force before the optimized approach.

Share this article

Test your knowledge

Take a quick quiz based on this chapter.

hardDSA Interview Patterns
Quiz: Maximum Rectangle from Coordinates
6 questions10 min

0 comments

Please login to comment.
No comments yet.
Lesson 10 of 13 in Company Asked Variants
Previous in Company Asked Variants
Two Stock Arrays with Switching Cost
Next in Company Asked Variants
Circle Group Connectivity
Back to DSA Interview Patterns Roadmap
Back to moduleCategories