I like to keep my brain sharp by working on programming puzzlers. On off weeks I'm going to start posting programming puzzlers I've collected over the years. Hopefully you'll find them as entertaining as I do.
The Problem
Given an unbounded sequence of characters, find the value and position of the first non-repeated character.
e.g., in the stream: A,B,C,D,C,B,A,F,A,F the first non-repeated character is D.
For the purposes of this exercise, consider the following interface as the source of the stream:
1: // C#
2: public interface ICharStream
3: {
4: bool HasNext { get; }
5: char GetNext();
6: }
Spoiler Alert
Fair Warning: discussion of the problem and potential solutions may be discussed in the comments below.