Ctrl K

Columns That Cover Rows

Medium
You are given a table grid of zeros and ones and a number picks. Mark exactly picks distinct columns. A row is covered when every one in it sits in a marked column. A row with no ones is always covered. Return the largest number of rows you can cover by marking picks columns.
Example 1
grid=[[1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 0]], picks=1 → 2

Marking column 0 covers rows 0 and 3 (row 3 has no ones at all). Column 1 also covers two rows, column 2 only row 3. No single column covers more than two rows.

Example 2
grid=[[0, 1], [1, 1], [1, 0]], picks=2 → 3

Both columns are marked, so every row is covered and the answer is 3.

Constraints
  • 1 ≤ grid.length ≤ 12
  • 1 ≤ grid[i].length ≤ 12, all rows have the same length
  • grid[i][j] is 0 or 1
  • 1 ≤ picks ≤ grid[0].length
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPicks With the Full OR MediumOutshoot the Rival MediumStrongest Product Team MediumMoves Between Offices HardXOR of Every Subset Easy
loading Python…
Input
grid=[[1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 0]], picks=1
Expected
2

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