Skip to content

Create 3170. Lexicographically Minimum String After Removing Stars #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions 3170. Lexicographically Minimum String After Removing Stars
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution {
public:
bool find(int target,vector<int>&arr){
int l = 0;
int r = arr.size()-1;
int ans = -1;
while(l<=r){
int mid = l + (r-l)/2;
if(arr[mid]==target){
return true;
}
else if(arr[mid]<target){
l = mid + 1;
}
else{
r = mid - 1;
}
}
return false;
}
string clearStars(string s) {
map<char,vector<int>>mp;
for(int i=0;i<s.length();i++){
if(s[i]!='*'){
mp[s[i]].push_back(i);
}
if(s[i]=='*'){
char ch = mp.begin()->first;
mp[ch].pop_back();
if(mp[ch].size()==0){
mp.erase(ch);
}
}
}
string ans = "";
for(int i=0;i<s.length();i++){
if(find(i,mp[s[i]])){
ans.push_back(s[i]);
}
}
return ans;
}
};
Loading