Leetcode.com problem 1465: "Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts"

James S. Plank

Sat Jul 2 07:09:11 PM EDT 2022

To be honest with you, I'm not sure why this one has a sub-50% acceptance rate. My guess is that the non-acceptances had one of three problems: The first things you should do is add 0 and h to the horizontal cuts, and 0 and w to the vertical cuts. Now you only have to deal with the cuts. Next, sort the vectors using sort() from the STL++ algorithms. The answer is going to be the maximum difference between adjacent horizontal cuts times the maximum difference between adjacent vertical cuts, modulo that big number.

That one got me 91ms, faster than 70.82% of C++ submissions.