#C1597. Minimum Operations for Lexicographical Superiority
Minimum Operations for Lexicographical Superiority
Minimum Operations for Lexicographical Superiority
Devu has two strings: \(s\) and \(t\). His goal is to make \(s\) lexicographically greater than \(t\) by performing a minimal operation. In one operation, he can choose an index \(i\) (0-indexed) where \(s[i] \le t[i]\) and replace \(s[i]\) with the smallest character that is strictly greater than \(t[i]\) (i.e. replace \(s[i]\) with \(\text{chr}(\text{ord}(t[i])+1)\)).
If \(s\) is already lexicographically greater than \(t\), no operations are needed. Your task is to determine the minimum number of operations required to achieve this goal.
Note: The two strings are assumed to be of the same length.
Example:
For \(s = \texttt{abc}\) and \(t = \texttt{bcd}\), replacing \(s[0]\) (because \(\texttt{'a'} \le \texttt{'b'}\)) with \(\texttt{'c'}\) makes \(s\) become \(\texttt{cbc}\) which is lexicographically greater than \(\texttt{bcd}\). Hence, the answer is 1.
inputFormat
The input consists of two lines:
- The first line contains the string \(s\).
- The second line contains the string \(t\).
Both strings are guaranteed to be of the same length and contain only lowercase English letters.
outputFormat
Output a single integer denoting the minimum number of operations required so that the string \(s\) becomes lexicographically greater than \(t\). The result should be printed to stdout.
## sampleabc
bcd
1