-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode Username
cocwarrior16112004
Problem Number, Title, and Link
- Equal Sum Grid Partition II https://leetcode.com/problems/equal-sum-grid-partition-ii/description/
Bug Category
Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Bug Description
The Question state that if we discount a digit from either one side of the Partition, the discount should not make the section disconnected.
But the Leet Code Testcase are so inefficient, that they get accepted on just discounting only the 4 corners element.
Language Used for Code
Java
Code used for Submit/Run operation
class Solution {
public boolean canPartitionGrid(int[][] grid) {
int m = grid.length;
int n = grid[0].length;
long s = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) s += grid[i][j];
}
// checking vertical cut
long s1 = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m; j++) {
s1 += grid[j][i];
}
if (s1 == s - s1) {
return true;
}
if (s1 - grid[0][0] == s - s1) {
return true;
}
if (s1 - grid[0][i] == s - s1) {
return true;
}
if (s1 - grid[m - 1][0] == s - s1) {
return true;
}
if (s1 - grid[m - 1][i] == s - s1) {
return true;
}
if (s1 == s - s1 - grid[0][n - 1]) {
return true;
}
if (s1 == s - s1 - grid[0][i + 1]) {
return true;
}
if (s1 == s - s1 - grid[m - 1][i + 1]) {
return true;
}
if (s1 == s - s1 - grid[m - 1][n - 1]) {
return true;
}
}
// checking horizontal cut
long s2 = 0;
for (int i = 0; i < m - 1; i++) {
for (int j = 0; j < n; j++) {
s2 += grid[i][j];
}
if (s2 == s - s2) {
return true;
}
if (s2 - grid[0][0] == s - s2) {
return true;
}
if (s2 - grid[0][n - 1] == s - s2) {
return true;
}
if (s2 - grid[i][0] == s - s2) {
System.out.println(13);
return true;
}
if (s2 - grid[i][n - 1] == s - s2) {
return true;
}
if (s2 == s - s2 - grid[i + 1][0]) {
return true;
}
if (s2 == s - s2 - grid[i + 1][n - 1]) {
return true;
}
if (s2 == s - s2 - grid[m - 1][0]) {
return true;
}
if (s2 == s - s2 - grid[m - 1][n - 1]) {
return true;
}
}
return false;
}
}Expected behavior
in this testcase , my solution is giving a False output , and the Leetcode solution is also giving False as output , But the ans should be TRUE.
Screenshots
No response
Additional context
No response
