Stack || Java || Easy Approach with explanation
\nclass Solution\n{//T->O(n) , S->O(n)\n    public String smallestSubsequenceString s)\n    {\n        Stack<Character> stack=new Stack<>();//for storing the ch
```\nclass Solution\n{//T->O(n) , S->O(n)\n    public String smallestSubsequenceString s)\n    {\n        Stack<Character> stack=new Stack<>();//for storing the character in lexiographical orer\n        int[] freq=new int[26];//for calculating the frequency of the alphabet \n        boolean[] exists=new boolean[26];//alphabet either exits in the stack or not (default all are false )\n        \n        for(int i=0;i<s.length();i++)//traversing \n        {//while we are dealing with minus in character ASCII substraction is done \n            char ch=s.charAt(i);\n            freq[ch-\'a\']+=1;//calculating the frequency i.e; a=0,b=1,...\n        }\n        \n        for(int i=0;i<s.length();i++)//traversing \n        {\n            char ch=s.charAt(i);//extracting the Character\n            \n            freq[ch-\'a\']-=1;//as we are dealing with that Character, we are decreasing its frequency\n            \n            if(exists[ch-\'a\']==true)//if it already exits in the stack we proceed to next character \n                continue;//moves to the next iteration \n            \n            while(stack.size()>0 && stack.peek() >ch && freq[stack.peek()-\'a\']>0)//if stack top element is greater than the current element and the f>0\n            {\n                exists[stack.pop()-\'a\']=false;//we pop it and flag it with false as its removed \n            }\n            \n            stack.push(ch);//pushing the character if it is greater than the previous(top)\n            exists[ch-\'a\']=true;//making the flag true \n        }\n        \n        char[] res=new char[stack.size()];//resultant array \n        int i=res.length-1;\n        while(i>=0)\n        {\n            res[i]=stack.pop();//popping\n\t\t\tand storing from backward \n            i-=1;\n        }\n        return new String(res);//returning the resultant String(as there is a constructor in String class )\n    }//Please do vote me, It helps a lot\n\t```\n}\n
['Stack', 'Java']