Loading...
You are given an array of binary strings strs (every character of every string is either '0' or '1') together with two integers maxZeros and maxOnes.
Choose a subset of strs (each string may be taken at most once, and the order of the chosen strings does not matter). Add up the number of '0' characters across all chosen strings, and likewise the number of '1' characters. The subset is valid when both totals stay within their limits: at most maxZeros zeros and at most maxOnes ones.
Return the number of strings in the largest valid subset.
The empty subset is always valid and uses no characters, so the answer is never negative; it is 0 when no single string fits within both limits.
Input: strs = ["10","0001","111001","1","0"], maxZeros = 5, maxOnes = 3
Output: 4
Explanation: Taking "10", "0001", "1" and "0" spends 5 zeros and 3 ones in total,
which is exactly the two limits, so this subset of size 4 is valid. No subset of
size 5 is: taking all five strings would need 9 zeros and 7 ones. The string
"111001" alone already contains 4 ones, more than maxOnes = 3.
Input: strs = ["10","0","1"], maxZeros = 1, maxOnes = 1
Output: 2
Explanation: Taking "0" and "1" spends 1 zero and 1 one. Adding "10" would push
both totals to 2, over the limits, so the answer is 2.
strs.length ≤100strs[i].length ≤100strs[i] consists only of the characters '0' and '1'maxZeros, maxOnes ≤100Click "Run" to test with sample cases or "Submit" to run all tests.