I got this question the other day for a solutions engineering position. Still can’t figure out how to resolve the edge cases. I’m not looking for feedback on my methodology, more so just how others might have gone about it.
The question is as follows:
There is a seesaw where someone sits, their weight is X. On the other side there are an infinite number of 16, 7, and 3 pound weights.
Write a program that finds the minimal number of a weights needed to balance the scale, or return 0 if there is no combination.
The interesting thing I found here, is that the natural tendency to gravitate towards the modulo operator is not really a winning solution.
Any thoughts or creative solutions for the community would be appreciated!
I used mod operator, but it doesn’t end up working for edge cases where there are weird combinations of weights.
For example, take the number 33. It consists of one 16 lb weight, two 14 lb weights, and one 3 lb weight. There isn’t a way you can use modulo to achieve those results.