Rectangle Area
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
Two axis-aligned rectangles are drawn on a 2D plane. Rectangle A has bottom-left corner (ax1, ay1) and top-right
corner (ax2, ay2); rectangle B has bottom-left corner (bx1, by1) and top-right corner (bx2, by2).
Return the total area covered by at least one of the two rectangles. Area covered by both is counted once.
Rectangles that only share an edge or a corner have no overlapping area. A rectangle may be degenerate
(zero width or height), in which case it contributes no area.
Examples
Constraints
- -10^4 <= ax1 <= ax2 <= 10^4
- -10^4 <= ay1 <= ay2 <= 10^4
- -10^4 <= bx1 <= bx2 <= 10^4
- -10^4 <= by1 <= by2 <= 10^4
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.