Bottle fill classification

Write codeEasy13 min

Your task

A bottling line records the volume in millilitres it poured into each bottle, in the order the bottles left the filler. Quality control reads that log against a target volume and a tolerance. A bottle is in spec when its volume differs from the target by no more than the tolerance in either direction, so a bottle sitting exactly on either edge of the band still counts as in spec. Return exactly three lists: the underfilled volumes, then the in spec volumes, then the overfilled ones. Inside each list keep the order the bottles were logged and keep repeats, since two bottles may pour the same volume. An empty log still returns three lists, all of them empty. The tolerance is never negative.

Examples

partition_fill_volumes(fills_ml: list[int], target_ml: int, tolerance_ml: int) -> list[list[int]]
Example 1
Inputpartition_fill_volumes([500, 496, 503, 488, 512], 500, 3)
Output[[496, 488], [500, 503], [512]]
Example 2
Inputpartition_fill_volumes([750, 750, 749], 750, 0)
Output[[749], [750, 750], []]
Example 3
Inputpartition_fill_volumes([], 330, 5)
Output[[], [], []]