#3081
Replace Question Marks in String to Minimize Its Value
expert · 1135 · lc medium +32 · 29% accepted · 205 likes · top 6%
Description
You are given a string s of lowercase letters and '?' characters. For a lowercase-only string t, define cost(i) as the count of characters equal to t[i] among the first i positions. The value of t is the sum of all cost(i). Replace every '?' in s with a lowercase letter to minimize the resulting value. Among all minimum-value solutions, return the lexicographically smallest.
Code
1
2
3