Closest snack drink combo
A vending kiosk shows snack calories and drink calories, each list sorted ascending and non-empty. A customer picks exactly one snack and one drink, aiming for combined calories as close as possible to a target; if two combos are equally close, they take the lower-calorie one. Return that combined calorie count. Use one pointer per list in a single O(n + m) walk. Example: snacks = [100, 250], drinks = [50, 120], target = 300 gives 300 (250 + 50).
Implement
closest_combo_sum(snacks: list[int], drinks: list[int], target: int) → intExamples
in
[[100,250],[50,120],300]out300What 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.
0:00 of about 15 min
solution.py
InputExpectedGot
[[100,250],[50,120],300]300not run yetsample