Color Cyclic Permutations

70 Views Asked by At

Suppose there are n people sitting in a circle,wearing 3 kind of shirts viz. white,red and green. When two people with different shirt color talk with each other, they both change their shirt to third color.

At i-th step, the 1st person talks with 2nd person, the 2nd talks with the 3rd ,… and the nth talks with 1st person.

Given the original color of shirts of n persons,find the color of shirts of n person after k steps.

Eg:n=5 and k=4 and initial colors are WRWRW then after 4 steps ans is: GGGWG

I tried with some cases of my own but could not come up with general algorithm!!Kindly help me with this??