All Tracks Algorithms String Algorithms Basics of String Manipulation Problem

Sumit's Task
/
No tags
Problem
Editorial
Analytics

One day Sumit's friend Himanshu got angry with him for not waking him in the morning, so he gave a tough task to Sumit to take the revenge.

"Given a string S consisting of letters 'O' and 'Z'. Calculate the minimum number of changes required such that all O's are adjacent to each other and all Z's are adjacent to each other. One change is equivalent to swapping two neighbouring letters."

Sumit needs your help to complete this task as it is difficult for him to solve alone.

Input :

  • The first line contains T - the number of test cases .
  • Each test case consists of a string S consisting of characters 'O' and 'Z' only.

Output :

  • Desired O/p

Constraints :

  • 1<=T<=10
  • 1<=|S|<= 10^6
SAMPLE INPUT
1
OOZOZO
SAMPLE OUTPUT
3
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

Initializing Code Editor...
Notifications
View All Notifications

?