root and a number goal, which may be fractional.
Return the bin number in the tree that is closest to goal. If two numbers are equally close (one below goal, one above), return the smaller one.
Walking the whole tree works, but try to use its ordering and follow a single path down from the root.root=tree_node([20, 9, 31, 4, 15]), goal=17.4 → 15
15 is the closest to 17.4: it is 2.4 away, while 20 is 2.6 away.
root=tree_node([20, 9, 31, 4, 15]), goal=25.5 → 20
20 and 31 are both 5.5 away from 25.5, a tie, so the smaller one, 20, wins.
root=tree_node([7]), goal=-3.0 → 7
root=tree_node([20, 9, 31, 4, 15]), goal=17.4
15
Run checks the first 3 tests in your browser. Submit checks all 42 tests on the server, hidden ones included.