From 08d87b4399b39b16250629bbe673ca9886e6be7f Mon Sep 17 00:00:00 2001 From: Sandhya Mishra <102294639+Sandhyamishra18@users.noreply.github.com> Date: Tue, 18 Oct 2022 16:38:01 +0530 Subject: [PATCH] Remove Duplicate Letters stack cpp solution Remove Duplicate Letters stack cpp easy solution Name : Sandhya Mishra Github Id : https://github.com/Sandhyamishra18 --- C++/Stack/Remove Duplicate Letters cpp | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 C++/Stack/Remove Duplicate Letters cpp diff --git a/C++/Stack/Remove Duplicate Letters cpp b/C++/Stack/Remove Duplicate Letters cpp new file mode 100644 index 0000000..ff90310 --- /dev/null +++ b/C++/Stack/Remove Duplicate Letters cpp @@ -0,0 +1,27 @@ + +string solve(string s){ +string res; +stack stk; +set present; +maplast; +for(int i=0;is[i] && last[stk.top()]>i){ + present.erase(stk.top()); + stk.pop(); + } + stk.push(s[i]); + present.insert(s[i]); +} +while(!stk.empty()){ + res+=stk.top(); + stk.pop(); +} +reverse(res.begin(),res.end()); +return res; +}