Farmer Frenzy Problem

Can you explain how to solve this DP problem. I am trying to find prefix sum of the grid. And checking for different points. but it is in O(N^4). Can you give a better approach?

Hey @adarsh_2001
The problem can be reduced to finding the maximum rectangle area in a histogram, multiple times.

After each row, you calculate the histogram built until that row, and that calculate the maximum area rectangle in that histogram.

For better understanding , refer this -: