This is a verified interview question from Jefeeerirs. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Minimum Swaps to Group All R Together - Jefeeerirs Online Assessment IIT Delhi" covers key patterns like Arrays.
"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**. --- ### Input Format * First line contains the string **S**. --- ### Output Format Print the minimum number of swaps required. --- ### Constraints * (1 <= |S|<= 2*10^5) --- ### Example 1 #### Input ```text WRRWRRW ``` #### Output ```text 1 ``` --- ### Example 2 #### Input ```text RRRR ``` #### Output ```text 0 ``` --- ### Example 3 #### Input ```text RWRWRW ``` #### Output ```text 1 ``` --- ### Explanation 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."
Join thousands of developers practicing for Jefeeerirs.