Count clusters covered by dashers
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Count clusters covered by dashers evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Constraints
- 1 <= m, n (matrices may also be empty, in which case return 0)
- D and U have identical dimensions m x n
- Every cell of D and U is 0 or 1
- Clusters use 4-directional (horizontal/vertical) adjacency only; diagonals do not connect
- A cluster qualifies only if EVERY one of its cells has D == 1
Examples
Input: ([[1,1],[1,1]], [[1,0],[0,1]])
Expected Output: 2
Explanation: Two single-cell clusters at (0,0) and (1,1); both have D==1, so both qualify.
Input: ([[1,0],[1,1]], [[1,1],[1,1]])
Expected Output: 0
Explanation: All four user cells form one cluster, but D[0][1]==0, so the cluster is not fully covered.
Hints
- Iterate over all cells; when you hit an unvisited user cell (U==1), it is the seed of a new cluster — flood-fill it.
- Use BFS or DFS with only the 4 orthogonal neighbors. Mark cells visited as you push them so you never count a cluster twice.
- Track a boolean for the current cluster: it stays true only if every visited cell also satisfies D[i][j]==1. Don't break early — you must mark the whole component visited even if it already fails coverage.
- Edge cases: empty matrix returns 0; a single user cell with no dasher under it does not qualify.