Code Room
CodingMediumcod-g1247
Subject HashingLevel Entry–Mid~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A radio show has a slot of exactly slot seconds left and wants to fill it with two tracks whose durations (in seconds) add up to slot exactly. The two tracks must come from different positions in the durations list, though their durations may be equal. Return the chosen pair as [shorter, longer] in ascending order. If several pairs fit, return the one whose shorter duration is smallest; if no pair fits, return an empty list. For example, durations [180, 240, 120, 300] with slot 420 gives [120, 300] rather than [180, 240].

Implement
duet_fill(durations: list[int], slot: int) → list[int]
Examples
in[[180,240,120,300],420]out[120,300]
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.