Tap here to switch tabs
Problem
Submissions

Problem: Find a Good Subset of the Matrix

med
30 min
Try to solve the Find a Good Subset of the Matrix problem.

Statement

Given a 00 indexed mimesnm imes n binary matrix grid.

A non empty subset of rows is considered good if the sum of elements in each column across the chosen subset is at most half of the size of the subset. That is, if the subset contains kk rows, the sum of elements in each column within those rows must not exceed ⌊k2⌋\lfloor \frac{k}{2} \rfloor.

Return an array containing the indices of the rows belonging to any good subset, sorted in ascending order. If there are multiple valid good subsets, return any of them. If no such subset exists, return an empty array.

Constraints:

  • m ==== grid.length

  • n ==== grid[i].length

  • 1≤1 \leq m ≤104\leq 10^4

  • 1≤1 \leq n ≤5\leq 5

  • grid[i][j] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find a Good Subset of the Matrix

med
30 min
Try to solve the Find a Good Subset of the Matrix problem.

Statement

Given a 00 indexed mimesnm imes n binary matrix grid.

A non empty subset of rows is considered good if the sum of elements in each column across the chosen subset is at most half of the size of the subset. That is, if the subset contains kk rows, the sum of elements in each column within those rows must not exceed ⌊k2⌋\lfloor \frac{k}{2} \rfloor.

Return an array containing the indices of the rows belonging to any good subset, sorted in ascending order. If there are multiple valid good subsets, return any of them. If no such subset exists, return an empty array.

Constraints:

  • m ==== grid.length

  • n ==== grid[i].length

  • 1≤1 \leq m ≤104\leq 10^4

  • 1≤1 \leq n ≤5\leq 5

  • grid[i][j] is either 00 or 11.