10 Boxes, 1 Weighing Puzzle (Identify the Lighter-Apple Box)
viaLeetCode
Problem: 10 boxes labeled 1-10, each containing 100 apples weighing 1kg each. One random box has all of its apples replaced with 0.9kg apples. Using a digital weighing scale that can only be read once, identify which box contains the lighter apples.
Constraints: Only a single weighing/reading is allowed.
Approach: Take a number of apples from each box equal to its label (1 apple from box 1, 2 from box 2, ..., 10 from box 10) and weigh them all together. If no box were lighter, the total would be (1+2+...+10) * 1kg = 55kg. The shortfall below 55kg, divided by 0.1kg (the per-apple deficit), gives the label of the lighter-apple box -- e.g. a total of 54.7kg is a 0.3kg shortfall, 0.3/0.1 = 3, so box 3 is the one with lighter apples.
asked …