← 返回 microsoft 的题目列表Minimum Swap To Correct String
类型:online_judge
Minimum Swap To Correct String
Given a string consisting only of uppercase and lowercase letters, your task is to determine the minimum number of swaps required to make the string follow a specific rule by swapping any two characters of the string.
Rule: For every uppercase letter, it must appear before its corresponding lowercase letter.
Example
Input: "aaAbcCABBc" Output: 2
Input: "xyzXYZabcABC" Output: 6
Input: "ABCabcAefG" Output: 0
Input Description
A string of positive length consisting of characters from 'a'-'z' and 'A'-'Z'.
Output Description
A single integer denoting the minimum number of swaps required to satisfy the rule.
Example
Input
aaAbcCABBc