Ones and Zeroes
You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.

30:00

Ones and Zeroes
medium
Topics
Companies

You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.

Example 1:
Input: {"strs":["10","0001","111001","1","0"],"m":5,"n":3}
Output: 4
Constraints:
  • 1strs.length6001 \leq \text{strs.length} \leq 600

  • 1strs[i].length1001 \leq \text{strs}[i].\text{length} \leq 100

  • strs[i] consists only of digits '0' and '1'.

  • 1m,n1001 \leq m, n \leq 100

Input
arr ={"strs":["10","0001","111001","1","0"],"m":5,"n":3}

Initialize DP table (6 × 4). Find max subset with ≤5 zeros and ≤3 ones.

Strings (max 5 zeros, 3 ones)
10
0001
111001
1
0
DP Table: dp[i][j] = max strings with i zeros, j ones
0
1
2
3
0
0
0
0
0
1
0
0
0
0
2
0
0
0
0
3
0
0
0
0
4
0
0
0
0
5
0
0
0
0
Variables
No variables to display
DepthFunction Call
Stack empty
0/11