Ctrl K

Lonely Dark Pixels

Medium
The image picture is a rectangular grid where every cell is either dark ("B") or light ("W"). A dark pixel is lonely when no other dark pixel shares its row or its column. Return the number of lonely dark pixels.
Example 1
picture=[["B", "W", "W"], ["W", "W", "B"], ["W", "W", "B"]] → 1

The corner pixel at (0, 0) is lonely. The two dark pixels in the last column spoil each other.

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

Both dark pixels are alone in their rows and columns.

Constraints
  • 1 ≤ number of rows, number of columns ≤ 500
  • Every cell is "B" or "W"
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 MediumDark Pixels in Twin Rows MediumMagic 3×3 Blocks Medium
loading Python…
Input
picture=[["B", "W", "W"], ["W", "W", "B"], ["W", "W", "B"]]
Expected
1

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