Answer: Firstly, we can replace the hash table with an array of pairs of size 26 (each representing a lowercase letter):
– The first element in each pair stores the location where the character occured for the first time in the string (default value is -1 indicating non-occurence).
– The second element in each pair is a boolean that indicates if the character’s occurence is unique. (default value is false and it also indicates repetition. true indicates uniqueness.)
With this data structure ready, it is enough if we parse through the original string only once to populate the array of pairs. Then we do a scan on the array to figure out the first unique character.
]]>