(1) Take a hash table of all characters
(2) Initialize them to 0
(3) For each character
      (3.1) If hash[character] == 0 then hash[character]=current loop
index      #Appearing for first time so store index at which it
appears
      (3.2) elsif hash[character] > 0 then hash[character]=-1
#Already occurred so reject it
(4) Loop through the hash table, the element with lowest positive
value is the first unrepeated character

Time complexity : O(n)

--------
Tips:
--------
If hash[character] is 0 then character has never occurred
if hash[character] is > 0 then character has occurred once at position
which is stored as hash value
if hash[character] is -1 then it has repeated.

'Coding is an art'

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to