All problems
0529MediumArrayMatrixEnumerationPrefix Sum

Splitting the Yield Plot in Two

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3546Equal Sum Grid Partition I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A field is surveyed as plot, a grid of parcels where plot[r][c] is the yield of one parcel. Every yield is at least 1.

The field is to be divided between two tenants by a single straight fence. The fence runs the whole way across the field, either along a line between two rows of parcels or along a line between two columns, and it never cuts through a parcel. Both sides must get at least one parcel.

Return true if some such fence gives the two sides the same total yield, and false otherwise.

Examples

Example 1

Input
plot = [[4, 1], [2, 3]]
Output
true

A fence between the two rows gives the top side 4 + 1 = 5 and the bottom side 2 + 3 = 5.

Example 2

Input
plot = [[3, 1], [2, 4]]
Output
true

A fence between the two columns gives the left side 3 + 2 = 5 and the right side 1 + 4 = 5.

Example 3

Input
plot = [[2, 1], [1, 4]]
Output
false

The whole field yields 8. The fence between the rows gives 3 and 5, and the fence between the columns gives 3 and 5, so no fence splits it evenly.

Constraints

  • 1 <= rows == plot.length <= 10^5
  • 1 <= cols == plot[r].length <= 10^5
  • 2 <= rows * cols <= 10^5
  • 1 <= plot[r][c] <= 10^5

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def can_split_plot(plot: list[list[int]]) -> bool:
Java
public boolean canSplitPlot(int[][] plot)
September 7
Apply