Was asked this DSA Question -
At a team event, engineers at Uber are sitting around a circular table playing a modified Rock–Paper–Scissors game.
Each engineer secretly chooses one of:
'R' → Rock
'P' → Paper
'S' → Scissors
After revealing their choices, every engineer compares their choice with their two immediate neighbors.
Two neighbors tie if they choose the same option.
Uber wants to make the game more interesting by ensuring no ties occur between any pair of neighbors.
You are allowed to ask any engineer to change their choice to either of the other two options.
Your task is to compute the minimum number of engineers whose choice must be changed so that no two adjacent engineers choose the same option.
Note that the engineers sit in a circle, so the first and last engineers are also neighbors.
Function Signature
int minChanges(string choices);
Input
A string choices of length n representing the selections of engineers sitting clockwise.
choices[i] ∈ {'R','P','S'}
Constraints
3 ≤ n ≤ 2 * 10^5
The arrangement is circular.
Example 1
Input
PRSSP
Output
2
Explanation
Two neighboring pairs have the same choice:
P R S S P
↑
S S
and the first and last:
P .... P
Changing two engineers is enough to remove all ties.
Example 2
Input
RRRRRRR
Output
4
Example 3
Input
RSPRPSPRS
Output
0
No adjacent engineers choose the same option.