The problem
Background. Pack sized, valued items into a fixed sequence of bins. Each bin has a finite integer capacity and a fixed index (0..B-1). Each item has a size, a value and a soft deadline expressed as a bin-index threshold: assigning an item to a bin with index greater than its deadline is allowed but incurs a lateness penalty. Dropping an item (assigning None) is also allowed but incurs a drop penalty. The objective trades keeping items on-time, tolerating late placements, and possibly dropping items to maximize a linear score.
Implement the solve(instance) function in solution.py.
INPUT FORMAT
- instance: lib.Instance with fields:
- bins: List[int] — capacities for bins indexed 0..B-1 (each a positive int).
- items: List[lib.Item] — each item is an object with attributes (item.size, item.value, item.deadline):
- size: int (>0) — space required in a single bin.
- value: int (>0) — contribution to the objective when kept (subject to penalties).
- deadline: int (>=0) — latest bin index for on-time placement; bins with index > deadline cause the item to be considered LATE.
- late_penalty_factor: float (>=0) — multiplier applied to the total value of LATE items.
- drop_penalty_factor: float (>=0) — multiplier applied to the total value of DROPPED items.
- name: optional string (ignored by scoring).
OUTPUT FORMAT
- Return a list of length len(items). For each item index i the entry must be either:
- an integer j with 0 <= j < len(bins) indicating the bin index item i is assigned to, or
- None to indicate the item is dropped.
- Validity rules:
- Each item must be assigned exactly one of (int bin index) or None.
- For every bin, the sum of sizes of items assigned to that bin must not exceed that bin's capacity.
SCORING (higher is better)
- Let S_on be the sum of values for items assigned to bins with index <= item.deadline (on-time).
- Let S_late be the sum of values for items assigned to bins with index > item.deadline (late).
- Let S_drop be the sum of values for items assigned None (dropped).
- Score = S_on - late_penalty_factor * S_late - drop_penalty_factor * S_drop.
- Maximize this score. Late placements and drops reduce the objective by their respective penalty factors multiplied by the items' values.
WORKED EXAMPLE
Input (JSON): { "bins": [5, 5, 5], "items": [ {"size": 2, "value": 10, "deadline": 0}, {"size": 3, "value": 8, "deadline": 1}, {"size": 4, "value": 6, "deadline": 0}, {"size": 2, "value": 5, "deadline": 2} ], "late_penalty_factor": 1.0, "drop_penalty_factor": 2.0, "name": "example-1" }
A valid return value (Python list): [0, 1, 2, 0]
This assignment respects bin capacities (bin loads: bin0=2+2=4, bin1=3, bin2=4) and places item 2 late (bin 2 > deadline 0). No items are dropped.
Submit runs solve() on several generated instance sets (their sizes are in the constraints). For each set, the average score must reach a fixed threshold; the exact optimum is not required.
Done when Submit goes green.
Input: {"bins": [5, 5, 5], "items": [{"size": 2, "value": 10, "deadline": 0}, {"size": 3, "value": 8, "deadline": 1}, {"size": 4, "value": 6, "deadline": 0}, {"size": 2, "value": 5, "deadline": 2}], "late_penalty_factor": 1.0, "drop_penalty_factor": 2.0, "name": "ex1"}Output: [0, 1, 2, 0]
Per-bin capacities are respected. Item 2 is assigned to bin 2 (> deadline 0) and is therefore LATE; no items are dropped.
Input: {"bins": [3, 3], "items": [{"size": 2, "value": 5, "deadline": 0}, {"size": 2, "value": 4, "deadline": 0}, {"size": 2, "value": 7, "deadline": 1}], "late_penalty_factor": 0.5, "drop_penalty_factor": 1.5}Output: [0, null, 1]
Bin capacities (3) prevent placing all three size-2 items; item 1 is dropped (None/null). The other two items fit into bins 0 and 1 respectively; both are on-time.
Constraints
- Python 3.12+ standard library only
- Time limit: 10 seconds per test file, shared by all instances in that file
- Only solution.py is editable
- Scored instances: 3..4 bins with capacities 5..38, 3..18 items per instance
- Item sizes 1..35, values 2..1421, deadlines 0..3; penalty factors 0.2..2.0
The files you get
- Yours to edit: solution.py.
- Read-only: lib.py.
- Tests you can read and run: public_tests/test_stage_2.py. Hidden tests run on Submit.
The round: an agent in the editor
The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.
Frequently asked, briefly answered
Is Deadline-Aware Bin Packing free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
No single company. It is practice for the format itself: an existing codebase, an assistant in the editor and a bar that rises stage by stage.
Do I bring my own AI tool?
No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.
What does the interviewer ask?
One question at the end about the whole session, your own code and your decisions. Your answer goes into the report.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, the AI coding interview guide.