1023. Remove All Duplicates from a String

Given a string s, remove all duplicate characters while preserving the order of their first appearance. Return the resulting string with only the first occurrences of each character.

Example 1:

Input: s = "bcabc"

Output: "bca"

Explanation: The first occurrence of 'b', 'c', and 'a' are kept. Duplicates are removed.

Example 2:

Input: s = "cbacdcbc"

Output: "cbad"

Explanation: Keep the first occurrence of each character: 'c', 'b', 'a', 'd'.

Now Your Turn!

Pick the correct output for the given input

Input: s = "aaaa"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s contains only lowercase English letters ('a' to 'z')
0
class Solution {
public:
string removeDuplicates(const string& s) {
// Your code goes here
}
};
Test Case

Input:

S