Amazon Online Assessment (OA)  Roll Dice
Given N
dices each face ranging from 1
to 6
, return the minimum number of rotations necessary for each dice show the same face.
Notice in one rotation you can rotate the dice to the adjacent face.
For example, you can rotate the dice shows 1
to show 2
, 3
, 4
, or 5
. But to make it show 6, you need two rotations.
Input
The input consists of three arguments:
N
: a list of integer represent dices each face ranging from 1 to 6
Output
return the minimum number of rotations necessary for each dice show the same face
Examples
Example 1:
Input:
N = [6, 5, 4]
Output: 2
Example 2:
Input:
N = [6, 6, 1]
Output: 2
Example 3:
Input:
N = [6, 1, 5, 4]
Output: 3
Try it yourself
1  1 
 
2  2  
3  3 
 
4   
 
4  + 
 
5  + 
 
6  + 
 
7  + 
 
8  +  
5  9 
 
6  10 
 
7  11 
 
8  12 

Loading full content...