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
from typing import List
2
2
3
3
def numberOfRotations(dice: List[int]) -> int:
4
-
    # WRITE YOUR BRILLIANT CODE HERE
4
+
    return min(
5
+
        sum(0 if d == v else 1 if d + v != 7 else 2 for d in dice)
6
+
        for v in range(1, 7)
7
+
    )
8
+
5
9
if __name__ == "__main__":
6
10
    N = [int(y) for y in input().split()]
7
11
    result = numberOfRotations(N)
8
12
    print(result)