Perfect Rectangle
From LeetCode. Exact cover check. Solve the geometry problem "Perfect Rectangle".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
Two conditions are both necessary and sufficient: (a) the sum of all rectangle areas equals the area of the overall bounding box, and (b) the set of corner points appearing an odd number of times contains exactly 4 points — the bounding box corners.
For each rectangle, toggle its 4 corners in a set: add if absent, remove if present. At the end, the set must contain only the 4 corners of the overall bounding rectangle.
The area check alone can pass with overlapping regions that cancel gaps, and the corner check alone can pass with disconnected shapes. Both must hold. Watch for integer overflow on large inputs (area of coordinates up to 10⁵).
Perfect Rectangle
**From LeetCode.** Exact cover check. Solve the geometry problem "Perfect Rectangle".