Nearest shim thickness
A machine shop stocks shim washers in a drawer, one entry per stocked thickness in microns, and thicknesses arrives sorted ascending. A thickness can be listed more than once. A machinist measuring a gap of target_um will fit the stocked thickness nearest to that gap, from either side of it. Given thicknesses and target_um, return that thickness itself, not its position in the drawer. When two stocked thicknesses sit exactly the same distance from the gap, return the thinner of the two, since a shim that is a little thin can be doubled up and one that is too thick cannot be shaved. Return -1 when the drawer is empty. Thicknesses are positive, and the drawer is large enough that reading every entry per lookup is too slow.
nearest_shim_thickness(thicknesses: list[int], target_um: int) → int[[50,100,250,400],180]out250[[50,100,250,400],175]out100[[],90]out-1State 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.
[[50,100,250,400],180]250not run yetsample[[50,100,250,400],175]100not run yetsample[[],90]-1not run yetsample