Equal Sum Grid Partition I
Real-world version: Splitting the Yield Plot in TwoThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def can_split_plot(plot: list[list[int]]) -> bool:public boolean canSplitPlot(int[][] plot)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Matrix Block SumReal-world version: Neighbourhood Totals On A Sensor PanelMedium
- Construct Product MatrixReal-world version: Cross Product PanelMedium
- Get Biggest Three Rhombus Sums in a GridReal-world version: Three Best Diamond Outlines on a BoardMedium
- Removing Minimum Number of Magic BeansReal-world version: Levelling the Seed SacksMedium