Suppose we have X amount of "?". We will keep a list L where initially we will store (K - X) alphabatically smaller hidden letters.

Now we take an empty string R. We iterate from left to right of string S. Whenever we will get a character in string S, we will add it to R.
If we get "?", then we will pick the smallest character in our list and add it to R.

"?" will be replaced by atleast one character. That's why we must replace it with the smallest letter in our list. Do we need to put more letters in this position or not, that depends on the following facts.

Suppose our string is ?DDA...... If our list contains characters alphabatically smaller than D, we should put them all in that "?".

If we have some D in our list, we have to search for first character after the "?" which is not equal to D. If it is alphabatically larger than D, we need should put all the D, otherwise save them for later.

Statistics

24% Solution Ratio
riyad000Earliest, Jul '20
NiloyDas19Fastest, 0.2s
Kuddus.6068Lightest, 4.9 MB
Kuddus.6068Shortest, 885B
Toph uses cookies. By continuing you agree to our Cookie Policy.