#3548
Equal Sum Grid Partition II
international master · 2180 · lc hard +32 · 21.7% accepted · 40 likes · top 2%
Description
Given a positive-integer matrix grid, determine if a single horizontal or vertical cut exists such that the two resulting non-empty sections have equal sums, or can be balanced by excluding at most one cell (from either section), provided the remaining section stays connected.
Return true if possible; otherwise false.
Note: Connectivity means every cell in the section is reachable from any other via up/down/left/right moves within the section.
Code
1
2
3