Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
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
A rectangular cake has height h and width w. horizontalCuts[i] is the distance from the top edge to the i-th horizontal cut, and verticalCuts[j] is the distance from the left edge to the j-th vertical cut. Cut positions are distinct within each array and lie strictly inside the cake, but they are **not** sorted.
After making every cut, return the largest area among the resulting pieces. Because the area can be huge, return it modulo 10^9 + 7. Take the modulo only at the end: find the true maximum area first.
Target O(H log H + V log V) time.
Examples
Constraints
- 2 <= h, w <= 10^9
- 1 <= horizontalCuts.length <= min(h - 1, 10^5)
- 1 <= verticalCuts.length <= min(w - 1, 10^5)
- 1 <= horizontalCuts[i] < h and 1 <= verticalCuts[i] < w
- All values within each cuts array are distinct
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.