Test case 113 wrong? C++


  • 0
    S

    The input in test 113 is

    ["WBBWWBWWWWWBBWW", "WBBWWBWWWWWBBWW", "WWWWWBBBWBWWWWB", "WWBWBWWWWBBWBWW", "WBBWWBWWWWWBBWW", "WWBWBWWWWBBWBWW", "WWBWBWWWWBBWBWW", "WWBWBWWWWBBWBWW"] 5

    My code is as below. It fails in test 113. I personally found 2 Black pixels that fit in the criteria but the test expects my result to be 0.

    Could you guys also tell if i am making any mistakes?

    public:
    	int findBlackPixel(std::vector<std::vector<char>> &picture, int N) {
    		int rows = picture.size();
    		int columns = picture[0].size();
    		if(rows == 0 || columns == 0)
    		{
    			return 0;
    		}
    		int total = 0;
    		std::vector<std::list<int>> colblacks(columns);
    		std::vector<int> brows(rows, 0);
    		std::vector<int> bcols(columns, 0);
    		std::unordered_set<int> satisfied_columns;
    		for(int i = 0; i < rows; i++)
    		{
    			for(int j = 0; j < columns; j++)
    			{
    				if(picture[i][j] == 'B')
    				{
    					brows[i]++;
    					bcols[j]++;
    					colblacks[j].push_back(i);
    				}
    			}
    		}
    		for(int i = 0; i < rows; i++)
    		{
    			for(int j = 0; j < columns; j++)
    			{
    				if(picture[i][j] == 'B')
    				{
    					if(brows[i] == N && bcols[j] == N)
    					{
    						if(satisfied_columns.count(j))
    						{
    							total += 1;
    							continue;
    						}
    						bool all_same = 1;
    						for(auto p : colblacks[j])
    						{
    							if(brows[p] != N)
    							{
    								all_same = 0;
    								break;
    							}
    						}
    						if(all_same)
    						{
    							total += 1;
    							satisfied_columns.insert(j);
    						}
    					}
    				}
    			}
    		}
    		return total;
    	}
    };

  • 0
    S

  • 0

    Hi @sri_hari,

    Could you pls tell me which 2 black pixels you found to fit the answer?

    I thought you meant this 'B':

    ["WBBWWBWWWWWBBWW",
    "WBBWWBWWWWWBBWW",
    "WWWWWBBBW'B'WWWWB",
    "WWBWBWWWWBBWBWW",
    "WBBWWBWWWWWBBWW",
    "WWBWBWWWWBBWBWW",
    "WWBWBWWWWBBWBWW",
    "WWBWBWWWWBBWBWW"]

    Please review the rule 2 in the problem description again.

    All the other 4 rows must have the same combination just like the row which this 'B' belongs to,

    but this row's combination is "WWWWWBBBWBWWWWB", where none of the other 4 four rows have the same combination like it.

    Best,
    LeetCode Contest Team.


  • 0
    S

    @love_FDU_llp it is the B in 3,2.......


  • 0

    @sri_hari

    ["WBBWWBWWWWWBBWW",
    "WBBWWBWWWWWBBWW",
    "WWWWWBBBWBWWWWB",
    "WW'B'WBWWWWBBWBWW",
    "WBBWWBWWWWWBBWW",
    "WWBWBWWWWBBWBWW",
    "WWBWBWWWWBBWBWW",
    "WWBWBWWWWBBWBWW"]

    You see, for this 'B', it has 7 'B' in its column.

    But for the rule I: Row R and column C both contain exactly N black pixels.


  • 0
    S

    @love_FDU_llp thank you! I found the bug.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.