Given a string str that may contain both lowercase and uppercase letters, your task is to remove all duplicate characters from str while preserving the order of their first occurrence.
Examples
Example 1
Input: "HappyProgramming"
Output: "HapyProgrmin"
Explanation: The resultant string is formed by retaining the first occurrence of each character.
Example 2
Input: "aAaAaA"
Output: "aA"
Explanation: The first occurrence of a and A is preserved, and the duplicates are removed.
Hints
Hint 1
Expected Time Complexity: O(N)
Hint 2
Expected Space Complexity: O(N)
Constraints
1 <= N <= 10^5
String contains uppercase and lowercase English letters.
Companies
AmazonMicrosoftSamsungAdobeTCS+ 1 more
Topics
StringStack
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.
Solution.csC#JavaPythonC++Javascript
1
2
3
4
5
6
7
8
9
10
Unlock the code editor
Sign in to write, run, and submit your solution against the full test suite.