Lonely Pixel II - Problem
Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels.
A black lonely pixel is a character 'B' that located at a specific position (r, c) where:
- Row
rand columncboth contain exactlytargetblack pixels. - For all rows that have a black pixel at column
c, they should be exactly the same as rowr.
Input & Output
Example 1 — Basic Case
$
Input:
picture = [["W","B","W"],["B","W","B"],["W","B","W"]], target = 2
›
Output:
2
💡 Note:
Row 1 has 2 black pixels and columns 0,2 each have 2 black pixels. All rows with black pixels in columns 0,2 are identical to row 1.
Example 2 — No Lonely Pixels
$
Input:
picture = [["W","B"],["B","W"]], target = 1
›
Output:
0
💡 Note:
Each black pixel's row and column have exactly 1 black pixel, but rows 0 and 1 are different, violating the identical row condition.
Example 3 — All Qualify
$
Input:
picture = [["B","B"],["B","B"]], target = 2
›
Output:
4
💡 Note:
All rows are identical with 2 black pixels each, and all columns have 2 black pixels each.
Constraints
- 1 ≤ m, n ≤ 200
- 1 ≤ target ≤ min(m, n)
- picture[i][j] is either 'W' or 'B'
Visualization
Tap to expand
Understanding the Visualization
1
Input Matrix
Black and white pixel matrix with target count
2
Check Conditions
Row count, column count, and identical row requirements
3
Count Result
Number of black pixels satisfying all conditions
Key Takeaway
🎯 Key Insight: Group identical rows to efficiently validate the 'same row' condition for all pixels in a column
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code