You're building the ultimate collection of binary strings, but there's a catch - you have limited resources! Given an array of binary strings and two constraints (maximum m zeros and n ones), find the largest possible subset you can create.
The Challenge: Each binary string costs a certain number of 0's and 1's. Your goal is to select the maximum number of strings while staying within your budget of m zeros and n ones.
Example: With strings ["10", "0001", "111001", "1", "0"], m=5 zeros, and n=3 ones, you could select ["10", "0001", "1", "0"] (using 3 zeros and 3 ones) for a subset of size 4.
Input & Output
Visualization
Time & Space Complexity
We fill a 3D table of size len Γ m Γ n, each cell taking O(1) time
3D DP table to store all possible states
Constraints
- 1 β€ strs.length β€ 600
- 1 β€ strs[i].length β€ 100
- strs[i] consists only of digits '0' and '1'
- 1 β€ m, n β€ 100