Lonely Pixel I

MediumMatrixhashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an m x n picture where each cell is either 'B' (black) or 'W' (white). A **lonely** black pixel is a 'B' cell whose row and whose column contain no other 'B'. Return the number of lonely black pixels.

Examples

Input: picture = [["W","W","B"],["W","B","W"],["B","W","W"]]
Output: 3
Each of the three black pixels is alone in both its row and its column.
Input: picture = [["B","B","B"],["B","B","W"],["B","B","B"]]
Output: 0
Every black pixel shares its row or column with another black pixel.

Constraints

  • m == picture.length
  • n == picture[i].length
  • 1 <= m, n <= 500
  • `picture[i][j]` is `'W'` or `'B'`

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems