🏆O(N)🏆 || ✅Explained in Video✅ || 🔥Begineer friendly🔥
Intuition\nVideo link for better understaning:\n\nhttps://youtu.be/rU5p0MRm5zU?si=Fy_mT3DgCZeT-X9i\n\n\n# Complexity\n- Time complexity:\n  O(N)\n\n- Space comp
# Intuition\n**Video link for better understaning:**\n\n[https://youtu.be/rU5p0MRm5zU?si=Fy_mT3DgCZeT-X9i]()\n\n\n# Complexity\n- Time complexity:\n  O(N)\n\n- Space complexity:\n  O(26)\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n      int n = s.size();\n      string result; // for final result store\n      vector<bool>taken(26,false); \n      vector<int>last_idx(26);\n\n      for(int i = 0 ; i< n ; i++){\n        char ch = s[i];\n        last_idx[ch - \'a\'] = i;\n      }\n\n      for(int i = 0 ; i < n ; i++){\n        char ch = s[i];\n        int idx = ch - \'a\';\n        if(taken[idx] == true) continue;\n        while(result.size() > 0 && result.back() > ch && last_idx[result.back() -\'a\'] > i){\n          taken[result.back() -\'a\'] = false;\n          result.pop_back();\n        }\n        result.push_back(ch);\n        taken[idx] = true;\n      } \n      return result;\n    }\n};\n```
['Monotonic Stack', 'C++']