Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
A medium-tier problem at 41% community acceptance, tagged with Array, Greedy, Sorting. Reported in interviews at BNY Mellon and 1 others.
You're given a rectangular cake with horizontal and vertical cuts, and you need to find the largest rectangular piece left after all cuts are made. BNY Mellon and IXL ask this one. The trick isn't about iterating through every possible rectangle. Instead, you find the largest gap between consecutive cuts in each dimension, multiply them, and that's your answer. Most candidates overcomplicate it by thinking in 2D when the problem is really two 1D problems stacked together. If you blank on this pattern during an OA, StealthCoder surfaces the working solution in seconds without the proctor seeing a thing.
Companies that ask "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts"
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe problem collapses once you recognize that the maximum piece is determined by the largest horizontal gap times the largest vertical gap. Sort the horizontal cuts, find the max distance between consecutive cuts (including edges at 0 and the cake height), do the same for vertical cuts, multiply them. Common failure: candidates try to track every possible rectangle or use nested loops, which fails on large inputs and misses the greedy insight entirely. The Array and Sorting components are straightforward, but the Greedy leap from 'what gaps matter' to 'only the largest gap in each dimension matters' trips people up under pressure. This acceptance rate of roughly 41% reflects that trap. When you hit this live and the brute force approach seems slow, StealthCoder gives you the linear-time greedy solution before self-doubt takes over.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts interview FAQ
Why do I only care about the largest gap in each dimension?+
Because any piece you cut is bounded by two consecutive cuts in each direction. If you pick the largest horizontal gap and largest vertical gap, you're guaranteed the maximum area. Choosing a smaller gap in either dimension gives you a smaller piece. It's greedy and provably optimal.
How do I handle the cake boundaries?+
Treat the edges (0 and the cake width/height) as implicit cuts. When you sort cuts and compute gaps, start from 0 and end at the cake dimension. That way the first piece and last piece are accounted for.
Is this still asked at major companies?+
Yes. BNY Mellon and IXL both report it. It's a clean medium-difficulty test of whether you can spot the greedy pattern instead of overthinking dimensionality. Companies like these use it to separate pattern-recognition from brute-force thinkers.
What's the time complexity?+
Sorting dominates. You sort horizontal and vertical cuts separately, which is O(n log n) where n is the number of cuts in the larger dimension. Finding max gaps is linear. That beats any nested-loop approach on large inputs.
What's the most common mistake?+
Trying to compute the area for every possible rectangle by picking one horizontal cut and one vertical cut. That's O(n squared) and gets TLE. The insight is that only two specific cuts matter: the ones surrounding the largest gap in each direction.
Want the actual problem statement? View "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts" on LeetCode →