Squats
Practice this coding question on Coding Gurukul.
Problem statement
A coach is arranging an even-sized exercise group for a synchronized routine. The attendance string records each participant as standing, X, or squatting, x. The next pose requires exactly half the group in each position, and every changed participant costs one instruction. Your task Change as few characters as possible so that the final string contains n/2 uppercase X characters and n/2 lowercase x characters. Print both the minimum number of changes and the final string. Important details Each change flips one participant between X and x. Among final strings needing the minimum number of changes, choose the lexicographically smallest, with X ordered before x. A balanced group requires zero changes and must retain its original string. Worked example For xxXx, exactly one of the squatting participants must stand. Changing the first character gives XxXx, which is the smallest optimal string under the stated ordering. For XXXX, two must squat; keeping the earliest uppercase letters gives XXxx with two changes.
Input format
Read even n, then a string of length n containing only X and x.
Output format
Print the minimum changes on line one and the chosen final string on line two.
Constraints
2 <= n <= 200; n is even.
Sample input
4 xxXx
Sample output
1 XxXx
Sign in to run or submit a solution in C++, Java or Python.