Skip to content
Veltoryx Technologies
ProProblem 145● Mediumleetcode ↗4 min readUpdated 30 October 2026

Ones and Zeroes

Maximize the number of chosen binary strings under two separate resource constraints using 2D 0/1 knapsack.

01The problem

You are given an array of binary strings strs and two integers m and n.

Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.

A set x is a subset of a set y if all elements of x are also elements of y.

Loading the rest of the lesson…