166. Ones and Zeroes
Medium · Dynamic Programming
You are given an array of binary strings and two limits: m (maximum zeros allowed) and n (maximum ones allowed). Find the size of the largest subset of these strings such that the total count of zeros across all strings in the subset does not exceed m, and the total count of ones does not exceed n.
Input: An array [strs, m, n] where strs is an array of binary strings (each containing only '0' and '1' characters), m is the maximum number of zeros you can use, and n is the maximum number of ones you can use.
Return: A single integer representing the maximum number of strings you can include in your subset while respecting both limits.
Examples
Example 1 Input: [["10","0001","111001","1","0"], 5, 3] Output: 4 Explanation: Pick "10","0001","1","0" — uses 4 zeros and 3 ones
Example 2 Input: [["10","0","1"], 1, 1] Output: 2 Explanation: Pick "0" and "1"
Constraints
- Standard input/output constraints apply