You are given a string S consisting only of the characters 'R' and 'W'.
In one operation, you may swap any two characters.
Determine the minimum number of swaps required to make all the 'R' characters appear consecutively.
Print the minimum number of swaps required.
WRRWRRW
1
RRRR
0
RWRWRW
1
For "WRRWRRW":
There are 4 occurrences of 'R'.
Choose a window of length 4. The best window contains only one 'W', so only one swap is needed.
Expert in Data Structures & Algorithms. Building tools to help developers crack FAANG interviews.
Jefeeerirs • Pending
Jefeeerirs • Pending
Texas • Pending
Texas • Pending
Barclays • Pending