4036. Lexicographically Largest String After Pair Transformations
You are given an integer array
nums.For each integer
xinnums, start with a string consisting of exactlyxlowercase'a'characters.You may perform the following operation any number of times (including zero):
- Choose two adjacent equal letters and replace them with the next letter in the alphabet.
For example,
"aa"can be replaced with"b", and"bb"can be replaced with"c". The pair"zz"cannot be replaced.For each
x, determine the lexicographically largest string that can be obtained.Return an array of strings where the
i^thstring is the answer fornums[i].A string
ais lexicographically larger than a stringbif, at the first position where they differ,acontains a letter that appears later in the alphabet than the corresponding letter inb. If the firstmin(a.length, b.length)characters are equal, the longer string is lexicographically larger.
1 | class Solution { |