Skip to content

Practice Equal Sum Grid Partition II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3548
LeetCode Problem

Equal Sum Grid Partition II

Problem Statement

Determine whether one horizontal or vertical cut can divide grid into two nonempty sections with equal sums, either immediately or after discounting at most one cell in total from either section. If a cell is discounted, the remaining cells in its section must stay connected through up, down, left, and right moves. Return whether such a partition exists.

Source: Equal Sum Grid Partition II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

# Example 3

Input
grid = [[1,2,4],[2,3,5]]
Output
false

# Example 4

Input
grid = [[4,1,8],[3,2,6]]
Output
false

Constraints

1 <= m == grid.length <= 10^5
1 <= n == grid[i].length <= 10^5
2 <= m * n <= 10^5
1 <= grid[i][j] <= 10^5

Related LeetCode Problems

Practice more problems similar to Equal Sum Grid Partition II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.