Floor division for negative amounts
transcript
A bank checks nearby entries. The amounts are minus one and one. Your buckets put them together. The check then reports a match. Why?
The allowed difference t is one. So the width is two. Each bucket should hold two values. One bucket should hold amounts within t.
Truncating division rounds toward zero. Minus one goes to bucket zero. So does one. Floor division rounds down. Minus one goes to bucket minus one.
With truncation, bucket zero holds three values. Every other bucket holds two values. So bucket zero is wider than it should be.
Bucket zero holds minus one, zero and one. That is wider than the other buckets. So amounts in it can differ by more than t.
In Python, use the double slash. In Java, call Math dot floorDiv. In JavaScript, use Math dot floor on the quotient.
Never truncate a negative bucket. Floor makes every bucket equal. Full breakdown in the lecture.