Skip to content

Missing Test Case - 73. Set Matrix Zeroes #16768

@UditJain2622004

Description

@UditJain2622004

Your LeetCode username

uditjain2622004

Category of the bug

  • Question
  • Solution
  • Missing Test Cases

Description of the bug

The tests can be passed with a trick.
For e,g. - Lets assume element at index [i][j] is a 0, we can set the whole row i and column j to some random number, lets say -999. And then later change all occurences of -999 to 0.
This trick will work as long as -999 does not appear in a row or column not containing a 0, which is the case with the current test cases.
This does not work if we replace -999 with ,lets say, 2, because 2 does appear in a row/column not containing a 0 in the current test cases.
This will reduce space complexity to O(1) but it is not a correct solution as it is only working because of lack of test cases.

Code you used for Submit/Run operation

class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        int num_rows = matrix.size();
        int num_cols = matrix[0].size();
        for(int i{0};i<matrix.size();i++){
            for(int j{0};j<matrix[0].size();j++){
                if(matrix[i][j] == 0){
                    for(int x{0};x<num_cols;x++){
                        if(!(matrix[i][x] == 0 || matrix[i][x] == -999))
                            matrix[i][x] = -999;
                    }
                    for(int x{0};x<num_rows;x++){
                        if(!(matrix[x][j] == 0 || matrix[x][j] == -999))
                            matrix[x][j] = -999;
                    }
                }
            }
        }

        for(int i{0};i<matrix.size();i++){
            for(int j{0};j<matrix[0].size();j++){
                if(matrix[i][j] == -999){
                    matrix[i][j] = 0;
                }
            }
        }
    }
};

Language used for code

C++

Expected behavior

With correct case, i should have got wrong answer. Instead, it got accepted successfully.

Screenshots

Additional context

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions