#K83137. Minimum Operations to Sort a String
Minimum Operations to Sort a String
Minimum Operations to Sort a String
Given an integer ( n ) and a string ( s ) consisting of lowercase English letters, determine the minimum number of operations needed to transform ( s ) into a non-decreasing (lexicographically sorted) order. An operation is implicitly defined as correcting any character that does not match the corresponding character in the sorted version of ( s ). In other words, if ( s_{sorted} ) is the string obtained by sorting ( s ) in non-decreasing order, the answer is given by: [ \sum_{i=0}^{n-1} [s[i] \ne s_{sorted}[i]], ] where ( [\cdot] ) is the indicator function that is 1 if the condition inside is true and 0 otherwise.
The task is to compute and output this sum.
inputFormat
The input is read from stdin and consists of two lines. The first line contains an integer ( n ) (the length of the string). The second line contains the string ( s ) of lowercase English letters.
outputFormat
Output the minimum number of operations (an integer) needed to transform the string into its lexicographically sorted version. The output should be printed to stdout.## sample
4
dcab
4