Single Occurrence Characters

Easy
0/40
1 upvote

Problem statement

You are given a string S. Your task is to process the string and identify all characters that appear exactly once.


From these unique characters, you must construct and return a new string. The characters in this new string must be ordered according to their first appearance in the original input string S.


If no character in the string S appears exactly once, you should return an empty string.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first and only line of input contains a single string S.


Output Format:
Print a single string containing all characters that appear exactly once, sorted by their first appearance in the input string.

If no such character exists, print an empty string (a new line).


Note:
The character comparison is case-sensitive. For example, 'a' and 'A' are considered two different characters.

The input string can contain any standard ASCII characters, including letters, numbers, symbols, and spaces.
Sample Input 1:
statistics


Sample Output 1:
ac


Explanation for Sample 1:
Count character frequencies: 's': 3, 't': 3, 'a': 1, 'i': 2, 'c': 1.
Identify characters that appear once: 'a' and 'c'.
Order them by first appearance: In "statistics", 'a' appears before 'c'.
The final output is ac.


Sample Input 2:
hello world


Sample Output 2:
he wrd


Explanation for Sample 2:
Count character frequencies: 'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1.
Identify characters that appear once: 'h', 'e', ' ', 'w', 'r', 'd'.
Order by first appearance: The result is constructed by picking these characters in their original order from "hello world".
The final output is he wrd.


Expected Time Complexity:
The expected time complexity is O(N).


Constraints:
1 <= length of S <= 10^6
The string S contains standard ASCII characters.

Time limit: 1 sec
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Single Occurrence Characters
Full screen
Console