Skip to main content
LeetCode 533, Medium. Topics: Array, Hash Table, Matrix. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 36 parametrized pytest cases, and a playground notebook:

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' located at a specific position (r, c) where:
  • Row r and column c both contain exactly target black pixels.
  • For all rows that have a black pixel at column c, they should be exactly the same as row r.

Examples

Example 1
Example 2

Constraints

  • m == picture.length
  • n == picture[i].length
  • 1 <= m, n <= 200
  • picture[i][j] is 'W' or 'B'.
  • 1 <= target <= min(m, n)

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026