Easy Stack Solution in C++


#1
string Solution::solve(string A) {
        stack <int> arr;
        vector <int> alpha(26,0);
        string y="";
        for(int i=0;i<A.size();i++)
        {
            alpha[A[i]-'a']++;
            string u="";
            int pp=arr.size();
            while (!arr.empty())
            {
                if(alpha[arr.top()-'a']==1)
                u+=arr.top();
                arr.pop();
            }
            
            if(pp==u.size() && alpha[A[i]-'a']==1)
            arr.push(A[i]);
            for(int j=u.size()-1;j>=0;j--)
            arr.push(u[j]);

            if(arr.empty())
            y+='#';
            else
            y+=arr.top();
    }
    return y;
}