Description
Solutions
Minimize Multiples Of Three
πRELATED PROBLEMS
Given an array where elements are multiples of 3 and some elements are not, if an element is not a multiple of 3, either add to or subtract from it to make it a multiple of 3.
Return the minimum number of times you need to add or subtract from a number to make all elements multiples of 3.
Function Description
Complete the function minimizeMultiplesOfThree
in the editor.
minimizeMultiplesOfThree
has the following parameter:
int arr[]
: an array of integers
Returns
int
: the minimum number of operations required
Example 1:
Input: arr = [12, 21, 3, 4]
Output: 1
Explanation:12, 21, and 3 are all multiples of 3, but 4 is not. To make 4 a multiple of 3, subtract 1 from it to get 3. The total number of operations made is 1 (by subtracting 1 from 4).
Example 2:
Input: arr = [4, 5]
Output: 2
Explanation:π°π°
Constraints:
π
π

Related Problems
Testcase
Result
Case 1
input:
output: