Perfect Rectangle
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Each entry rectangles[i] = [x1, y1, x2, y2] is an axis-aligned rectangle with bottom-left corner (x1, y1) and top-right corner (x2, y2), where x1 < x2 and y1 < y2.
Return true if the rectangles together tile one larger rectangle **exactly**: their union is a rectangle, with no gaps inside it and no area covered twice. Rectangles that only share an edge or a corner do not overlap. Otherwise return false.
Aim for O(n) expected time.
Examples
Constraints
- 1 <= rectangles.length <= 2 * 10^4
- -10^5 <= x1 < x2 <= 10^5
- -10^5 <= y1 < y2 <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.