{"id":"fabfe8b9-fe6b-46b5-8a97-0673ba476e33","name":"Remove Duplicate Letters","description":"1. Given a string s, remove duplicate letters so that every letter appears once and only once.\r\n2. You must make sure your result is the first in dictionary order among all possible results.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 10^4\r\n2. s consists of lowercase English letters.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nstring removeOuterParentheses(string s) \n {\n //Write your code here\n }\n \n int main(int argc, char **argv)\n{ \n string S;\n cin>>S;\n string ans = removeOuterParentheses(S); \n if(ans.length()==0) cout<<\" \";\n else cout<<ans;\n\n re"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String removeDuplicateLetters(String s) {\r\n return null;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String result = removeDuplicateLetters(read.readLine());\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"bcabc","sampleOutput":"abc\r\n","questionVideo":"https://www.youtube.com/embed/luCn7p2CIbI","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"aedf431a-a4f3-4cc5-b3f3-68fc7f269878","name":"Remove Duplicate Letters","slug":"remove-duplicate-letters","type":1}],"next":{"id":"b7608c75-f10b-4608-a921-6e6c85ba0a3d","name":"Remove Duplicate Letters Medium MCQ","type":0,"slug":"remove-duplicate-letters-medium-mcq"},"prev":{"id":"2b7dea43-7082-4dc8-b072-96f4e83c5b44","name":"Remove K Digits","type":3,"slug":"remove-k-digits"}}}

Remove Duplicate Letters

1. Given a string s, remove duplicate letters so that every letter appears once and only once. 2. You must make sure your result is the first in dictionary order among all possible results.

{"id":"fabfe8b9-fe6b-46b5-8a97-0673ba476e33","name":"Remove Duplicate Letters","description":"1. Given a string s, remove duplicate letters so that every letter appears once and only once.\r\n2. You must make sure your result is the first in dictionary order among all possible results.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 10^4\r\n2. s consists of lowercase English letters.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nstring removeOuterParentheses(string s) \n {\n //Write your code here\n }\n \n int main(int argc, char **argv)\n{ \n string S;\n cin>>S;\n string ans = removeOuterParentheses(S); \n if(ans.length()==0) cout<<\" \";\n else cout<<ans;\n\n re"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String removeDuplicateLetters(String s) {\r\n return null;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String result = removeDuplicateLetters(read.readLine());\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"bcabc","sampleOutput":"abc\r\n","questionVideo":"https://www.youtube.com/embed/luCn7p2CIbI","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"aedf431a-a4f3-4cc5-b3f3-68fc7f269878","name":"Remove Duplicate Letters","slug":"remove-duplicate-letters","type":1}],"next":{"id":"b7608c75-f10b-4608-a921-6e6c85ba0a3d","name":"Remove Duplicate Letters Medium MCQ","type":0,"slug":"remove-duplicate-letters-medium-mcq"},"prev":{"id":"2b7dea43-7082-4dc8-b072-96f4e83c5b44","name":"Remove K Digits","type":3,"slug":"remove-k-digits"}}}
plane

Editor


Loading...

Remove Duplicate Letters

medium

1. Given a string s, remove duplicate letters so that every letter appears once and only once. 2. You must make sure your result is the first in dictionary order among all possible results.

Constraints

1. 1 <= s.length <= 10^4 2. s consists of lowercase English letters.

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

bcabc

Sample Output

abc

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode