Skip to main content
All Questions

Find the largest subset of binary strings with at most m ones and n zeros in total.

Unlock detailed company stats for this questionUpgrade

Given an array of binary strings and two integers m and n, find the size of the largest subset such that the total number of 1s across the subset is at most m and the total number of 0s is at most n.

Example 1: strs = ["100","10","1","11","111"], m = 3, n = 0 gives 2 via ["1","11"]. Example 2: strs = ["10","0001","111001","1","0"], m = 5, n = 3 gives 4 via ["10","0001","1","0"]. Example 3: strs = ["10","1","0"], m = 1, n = 1 gives 2 via ["1","0"].

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.