Ctrl K

Bit Strings on a Budget

Medium
You get an array words of strings made of the characters 0 and 1, and two integers zeros and ones. Pick as many strings from the array as you can so that all the picked strings together contain at most zeros zeros and at most ones ones. Each string can be picked at most once. Return the largest number of strings you can pick.
Example 1
words=["01", "110", "0", "1000"], zeros=3, ones=2 → 2

Three strings never fit: any three of them need more than 3 zeros or more than 2 ones. Two fit, e.g. "01" and "0" (2 zeros, 1 one), so the answer is 2.

Example 2
words=["1", "1", "0"], zeros=1, ones=1 → 2

Take one "1" and the "0"; the second "1" no longer fits.

Constraints
  • 1 ≤ len(words) ≤ 600
  • 1 ≤ len(words[i]) ≤ 100
  • words[i] consists only of 0 and 1
  • 0 ≤ zeros, ones ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSplit Into Dictionary Words MediumA Phrase on a Ticker Board MediumWords Hidden in a Text MediumWord Growth Chain MediumBead String Without Twins Medium
loading Python…
Input
words=["01", "110", "0", "1000"], zeros=3, ones=2
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.