1263. Ones and Zeroes

HardDynamic Programming0/1 Knapsack

Given an array of binary strings and integers m and n, return the size of the largest subset of strings that uses at most m zeros and at most n ones in total. The input is JSON {strs, m, n}.

Input: JSON {strs, m, n}.

Output: Integer — the size of the largest valid subset.

Examples

Example 1
Input: {"strs":["10","0001","111001","1","0"],"m":5,"n":3}
Output: 4
Explanation: Four strings fit the budgets.
Example 2
Input: {"strs":["10","0","1"],"m":1,"n":1}
Output: 2
Explanation: Two strings fit.
Example 3
Input: {"strs":["0"],"m":0,"n":0}
Output: 0
Explanation: No budget for any string.

Constraints

Asked by

GoogleBloombergAmazonMeta
Solve this problem in the editor →