Ctrl K

Dark Pixels in Twin Rows

Medium
The image picture is a rectangular grid of dark ("B") and light ("W") cells, and you also get a number need. A dark pixel in row r and column c counts when both of these hold: - row r and column c each contain exactly need dark pixels; - every row that has a dark pixel in column c is identical to row r. Return the number of pixels that count.
Example 1
picture=[["B", "W", "B"], ["B", "W", "B"], ["W", "B", "W"]], need=2 → 4

Rows 0 and 1 are identical with 2 dark pixels each, and columns 0 and 2 also hold exactly 2. All four pixels in those rows count. Pixel (2, 1) has only one dark pixel in its row.

Example 2
picture=[["B", "B"], ["B", "W"]], need=2 → 0

For (0, 0) the counts match, but rows 0 and 1 differ. Column 1 and row 1 each hold only one dark pixel.

Constraints
  • 1 ≤ number of rows, number of columns ≤ 200
  • Every cell is "B" or "W"
  • 1 ≤ need ≤ min(number of rows, number of columns)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSudoku Board Without Clashes MediumZero Out the Crosses MediumMultiply Mostly-Zero Matrices MediumLonely Dark Pixels MediumMagic 3×3 Blocks Medium
loading Python…
Input
picture=[["B", "W", "B"], ["B", "W", "B"], ["W", "B", "W"]], need=2
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.