Loading
Loading
A parser reads a stream of symbols and must report the first symbol that appears exactly once in the whole stream.
Return the index of that symbol, or -1 if every symbol repeats.
symbols = "ccdbea"countsc:2 d:1 b:1 e:1 a:1scan index 0 (c)count 2 — skipscan index 2 (d)count 1 — answer is 23Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
d at index 2 is the first symbol appearing once.
Example 2
Every symbol repeats.