Untitled
unknown
c_cpp
a year ago
396 B
5
Indexable
string lexicographicallySmallestString(string S, int K) {
unordered_map<char, int> freq;
for (char c : S) {
freq[c]++;
}
string result = S;
for (int i = 0; i < S.size() && K > 0; i++) {
if (freq[S[i]] > 1) {
freq[S[i]]--;
S.erase(i, 1);
i--;
K--;
}
}
return min(result, S);
}
Editor is loading...
Leave a Comment