Explained with thought process - Using  min heap || Very simple
Thought process\n- We need to find the smallest char towrds left of a given \' \'. This is some what close to smallest item towrds left which can be solved by s
# Thought process\n- We need to find the smallest char towrds left of a given \'* \'. This is some what close to smallest item towrds left which can be solved by stack. But here we need to remove it and if we find another * then we need to delete the second smallest char and this is not possible using stack, as stack only track the one smallest item towards left. So I discarded this approach.\n- Next thought -> as we need to find all smallest items => basically we need to have a sorted list of all items from where we can fetch the smallest char in o(1). This can be done in two way -> add to a vector sort it each time or use a min heap where we always have the smallest item at the top. Min heap is the better option here as we don\'t have to access in between item but need to use the top item. This way problem is almost solved. \n- Now only two task pending is to handle the char of same type and char removal/final ans string generation. \n  - To handle the same type of characters case -> we simply write a comparator and the one highest insed will be at the top\n  - To genereate the string, its difficult to do it while we are finding the smallest one. As we need to remove one by one char each time which is a bit tidious process. So to solve this what we can do is to first mark the smallest chars while processing with a special character and later we can iterate and just skip out the special char from the final string. Again the special char can be any thing but as we have to remove * as well from the string we will select the special character as *. \n\n# Intuition\n- In place of deleting the smallest chars and \'* \' , we first identify the smallest char and replace it with \'* \' and finally only take out non \'* \' chars as answer.\n- To find out the smallest chars till a \'* \' we need to store all visited chars in a min heap along with the index. Inedx is needed to replace the original string char of that index to \'* \'\n\n# Approach\n- Create a min heap (priority queue) that stores the visited chars and its index in a pair\n- In the min heap the items are stored as smallest char appear at the top and if two chars are equal then we will keep the largest index at the top as that need to be removed first to achieve lexicographically smallest string\n- Now iterate over the string, \n  - if the char is not \'*\' then simply add it along with its index in to the min heap\n  - if the char is \'*\' then find the top element of the heap ( that is the smallest char with largest index when equal) and the idexed stored in the top is to be replaced by a \'*\' char in the actual string.\n- Finally, iterate one more time over string and now only take the non \'*\' chars in the ans variable\n\n# Complexity\n- Time complexity : O(N.logN)\n- Space complexity : O(N)\n\n# Code\n```\nstring clearStars(string s) {\n    auto comp = [](const pair<int, int>& a, const pair<int, int>& b){  //comparator to sort in priority queue\n        if(a.first == b.first) return a.second < b.second;\n        return a.first > b.first;\n    };\n    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(comp)> pq;\n    string ans = "";\n    for(int i = 0; i < s.size(); ++i){   \n        if(s[i] != \'*\') {                 // when not \'*\' then simply push the ith char and index i to the priority queue\n            pq.push({s[i], i});  \n        }else{\n            s[pq.top().second] = \'*\';     // when its \'*\', find the smallest index and rpelace that char with \'*\'\n            pq.pop();\n        }\n    }\n    for(auto c: s) (c != \'*\') && (ans += c); // take all chars as ans except the \'*\' chars\n    \n    return ans;\n}\n```\n\n\n\n---\n\n<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted\n\n---\n
['C++']