Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If you want to move a ball from box i to box j, you'll need abs(i-j) moves.
To move all balls to some box, you can move them one by one.
For each box i, iterate on each ball in a box j, and add abs(i-j) to answers[i].