X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Rubik's Cube
Medium Accuracy: 54.54% Submissions: 44 Points: 4

Representation of a Rubik's Cube:

Yellow face is Up

Orange face is Front

Green face is Left

Blue face is Right

Red face is Back

White face is Down

Since the center pieces are fixed, any face rotation wont changes the central pieces.

Now lets take a look at the nomenclature of Rubik's Cube moves:

R= clockwise 90âˆ˜ rotation of right face.

Ri=anti-clockwise 90âˆ˜ rotation of right face.

Similarly rest of the moves are illustrated below:

Now you will be given the description of a scrambled Rubik's Cube, your task is to print the description of cube after N given moves.

For eg, if the given cube is:

It will be represented as following:

UP
GWYWYYRWW
FRONT
GGRBORYYY
LEFT
YOWRGOOOB
RIGHT
BGRGBBBOO
BACK
GROWRBBRG
DOWN
RBOYWGWYW

Let's say we apply the following moves to the cube:

B B

The move will rotate back face 180âˆ˜ clockwise, now the cube is:

And its description will be:

UP
WYWWYYRWW
FRONT
GGRBORYYY
LEFT
OOWBGOROB
RIGHT
BGOGBRBOY
BACK
GRBBRWORG
DOWN
RBOYWGYWG

Example:

Input:
UP
GWYWYYRWW
FRONT
GGRBORYYY
LEFT
YOWRGOOOB
RIGHT
BGRGBBBOO
BACK
GROWRBBRG
DOWN
RBOYWGWYW
2
R R

Output:
UP
GWOWYGRWW
FRONT
GGBBOWYYG
LEFT
YOWRGOOOB
RIGHT
OOBBBGRGB
BACK
YRORRBRRG
DOWN
RBYYWYWYW

You don't need to read input or print anything. Your task is to complete the function newFormation() which takes the string array present[], which is of size 12 containing the faces and the face configurations, string array move[] and its size N as inputs and returns the vector of strings containing 12 lines, showing the final configuration of the cube as shown in example.
Note: faces must always come in the order shown in example above ie {"UP","FRONT","LEFT","RIGHT","BACK","DOWN"}.

Expected Time Complexity: O(N)
Expected Auxiliary Space: Constant

Constraints:
1 ≤ N ≤ 50

We are replacing the old Disqus forum with the new Discussions section given below.