Please give some hint for this i am passing only 2-3 test cases

1. `void solve(){`
2. `	string s;`
3. `    cin >> s;`
4. `    vector<ll> cnt(26,0);`
5. `    ll n = s.size();`
6. `    f(i,0,n){`
7. `        cnt[s[i]-'a']++;`
8. `    }`
9. `    string ans = "";`
10. `    stack<char> p;`
11. `    f(i,0,n){`
12. `        p.push(s[i]);`
13. `        cnt[s[i]-'a']--;`
14. `        while(!p.empty()){`
15. `            char x = p.top();`
16. `            int top = (int)(x-'a');`
17. `            ll pass = 1;`
18. `            f(i,0,top){`
19. `                if(cnt[i]!=0){`
20. `                    pass=0;`
21. `                    break;`
22. `                }`
23. `            }`
24. `            if(pass==1){`
25. `                ans+=x;`
26. `                p.pop();`
27. `                continue;`
28. `            }`
29. `            break;`
30. `        }`
31. `    }`
32. `    cout<<ans<<endl;`
33. `    return;`
34. `}`