Ones and Zeroes

Given an array of binary strings and two integers m and n, return the size of the largest subset of strings that contains at most m zeroes and n ones. This is a standard 0/1 knapsack problem with two resource constraints.

Input Format

strs = array of binary strings, m = zero budget, n = one budget

Output Format

maximum size of a subset within the zero/one budgets

Constraints

  • 1 <= strs.length <= 600; 1 <= strs[i].length <= 100; 0 <= m, n <= 100

Examples

Example 1:

Input:

strs = ["10","0001","111001","1","0"]
m = 5
n = 3

Output:

4

Explanation:

A largest valid subset has size 4.

Example 2:

Input:

strs = ["10","0","1"]
m = 1
n = 1

Output:

2

Explanation:

Choose "10" with either "0" or "1".

Loading...
Ones and Zeroes - Dp Knapsack DSA Problem