Ctrl K

Round to a Multiple of Three

Easy
Candies are packed in boxes, with amounts[i] candies in box i. Each box is to be shared equally among three kids, so every box must end up holding a multiple of three (zero counts). In one step you may add a single candy to any box or take a single candy out of any box. Return the smallest number of steps.
Example 1
amounts=[5, 9, 7] → 2

5 → 6 (one step), 9 is already a multiple of 3, 7 → 6 (one step). Two in total.

Example 2
amounts=[1, 1, 2] → 3

Each number is 1 away from the nearest multiple of three (0 or 3), so 3 steps in total.

Constraints
  • 1 ≤ len(amounts) ≤ 50
  • 1 ≤ amounts[i] ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board Easy
loading Python…
Input
amounts=[5, 9, 7]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.