587. First Non-Repeating Character in Stream

EasyStackQueueString

Process the characters of a string one at a time. After reading each character, report the first character so far that has appeared exactly once, or '#' if there is none. Return the concatenation of these answers, one per character. The input is JSON {stream}.

Input: JSON {stream}.

Output: String — the answers, one character per position.

Examples

Example 1
Input: {"stream":"aabc"}
Output: a#bb
Explanation: After a: a; after aa: none; after aab: b; after aabc: b.
Example 2
Input: {"stream":"aabbcc"}
Output: a#b#c#
Explanation: Each pair cancels the front.
Example 3
Input: {"stream":"z"}
Output: z
Explanation: Single unique character.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →