You are given a string S. Your task is to process this string and generate a new string (or sequence of numbers) based on the sequential count of each character's appearance.
The process is as follows:
1) Iterate through the input string from left to right. 2) For each character, determine how many times that specific character has appeared so far in the string. 3) If a character c is encountered for the 1st time, its count is 1. If it's encountered for the 2nd time, its count is 2, and so on. 4) Replace each character in the original string with its sequential count.The first line of input contains a single string S.
Print a single line containing the space-separated sequence of sequential counts corresponding to each character in the original string.
The counting is case-sensitive ('a' and 'A' are treated as different characters).
Spaces and other symbols should be counted just like letters.
aba
1 1 2
1. The first character is 'a'. It's the 1st time we've seen 'a'. Output: 1.
2. The second character is 'b'. It's the 1st time we've seen 'b'. Output: 1.
3. The third character is 'a'. It's the 2nd time we've seen 'a'. Output: 2.
The final sequence is `1 1 2`.
Hello World
1 1 1 2 1 1 2 1 3 1
- 'H': 1st time -> 1
- 'e': 1st time -> 1
- 'l': 1st time -> 1
- 'l': 2nd time -> 2
- 'o': 1st time -> 1
- ' ': 1st time -> 1
- 'W': 1st time -> 1
- 'o': 2nd time -> 2
- 'r': 1st time -> 1
- 'l': 3rd time -> 3
- 'd': 1st time -> 1
The expected time complexity is O(N), where N is the length of the string.
0 <= length of S <= 10^5
The string consists of standard ASCII characters.
Time limit: 1 sec
Time complexity is O(N), where N is the length of the string.