Answered step by step
Verified Expert Solution
Question
1 Approved Answer
D . Binary String Sorting time limit per test 2 seconds memory limit per test: 2 5 6 megabytes input: standard input output: standard output
D Binary String Sorting
time limit per test seconds
memory limit per test: megabytes
input: standard input
output: standard output
You are given a binary string consisting of only characters andor
You can perform several operations on this string possibly zero There are two types of operations:
choose two consecutive elements and swap them. In order to perform this operation, you pay coins;
choose any element from the string and remove it In order to perform this operation, you pay coins.
Your task is to calculate the minimum number of coins required to sort the string in nondecreasing order i e transform so that
cdots where is the length of the string after applying all operations An empty string is also considered sorted in non
decreasing order.
Input
The first line contains a single integer the number of test cases.
The only line of each test case contains the string consisting of only characters andor
The sum of lengths of all given strings doesn't exceed
Output
For each test case, print a single integer the minimum number of coins required to sort the string in nondecreasing order.
Example
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started