Code Room
CodingMediumcod-g032
Subject KnapsackLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given an array strs of binary strings and two budgets m and n. Choose the largest possible subset of strs such that the total number of '0' characters across the chosen strings is at most m and the total number of '1' characters is at most n. Return the size of that largest subset. There are at most 600 strings, each of length at most 100, and m, n are at most 100.

Implement
find_max_form(strs: list[str], m: int, n: int) → int
Examples
in[["10","0001","111001","1","0"],5,3]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.