#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
string clearStars(string A) {
string s = A;
priority_queue<char, vector<char>, greater<char>> pq;
vector<vector<int>> ind(26);
unordered_set<int> rs;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '*') {
rs.insert(i);
char ch = pq.top(); pq.pop();
pq.push(ch);
rs.insert(ind[ch - 'a'].back());
ind[ch - 'a'].pop_back();
if (ind[ch - 'a'].empty()) pq.pop();
continue;
}
if (ind[s[i] - 'a'].empty())
pq.push(s[i]);
ind[s[i] - 'a'].push_back(i);
}
string res = "";
for (int i = 0; i < s.size(); ++i) {
if (!rs.count(i)) {
res += s[i];
}
}
return res;
}
};
Clear stars
Start removal
C++
using namespace std;
class Solution {
public:
string clearStars(string A) {
string s = A;
priority_queue<char, vector<char>, greater<char>> pq;
vector<vector<int>> ind(26);
unordered_set<int> rs;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '*') {
rs.insert(i);
char ch = pq.top(); pq.pop();
pq.push(ch);
rs.insert(ind[ch - 'a'].back());
ind[ch - 'a'].pop_back();
if (ind[ch - 'a'].empty()) pq.pop();
continue;
}
if (ind[s[i] - 'a'].empty())
pq.push(s[i]);
ind[s[i] - 'a'].push_back(i);
}
string res = "";
for (int i = 0; i < s.size(); ++i) {
if (!rs.count(i)) {
res += s[i];
}
}
return res;
}
};
Clear stars
Start removal
C++
Company : BrowserStack
Role: Software Engineer(Backend)
Experience: 0- 1Years
Location: Mumbai /Remote
Apply now: https://browserstack.wd3.myworkdayjobs.com/en-US/External/job/Software-Engineer--Backend--Mumbai_JR102378
Telegram:- @allcoding1_official
Role: Software Engineer(Backend)
Experience: 0- 1Years
Location: Mumbai /Remote
Apply now: https://browserstack.wd3.myworkdayjobs.com/en-US/External/job/Software-Engineer--Backend--Mumbai_JR102378
Telegram:- @allcoding1_official