The Gap At Two
Weights [1, 3, 3, 5]. possible(x) is true when some subset sums to exactly x:
| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| possible | yes | yes | no | yes | yes | yes | yes | yes | yes | yes | no | yes | yes |
You want the smallest sum in that cannot be formed. Someone runs a standard first_true binary search over the predicate not possible(x) with lo = 0, hi = 12. It probes 6, then 10, then 8, then 9, and returns 10.
What went wrong?
Sign in to answer questions and track your progress
Sign In