On Aug 9, 11:45 am, Alfredo Cruz <[EMAIL PROTECTED]> wrote:
> Hi, yeah, in general I think that you already know the alphabet under which 
> you are working. So, either you work with >ASCII codes or Unicode codes so as 
> Chitta said you maintain an array with your alphabet sorted by their codes. 
> Then >you start scanning your string and for each character you see you 
> search for it in your codes array, you mark it as seen >and save the index.
But why save the index? If this is going to be a large array, you can
come up with a way in which you can associate the code with the index.
And then, you just need an extra variable to store the location of the
first position in the array which is not repeated. For every
character, see if it is repeated. If not, change the array content to
reflect it, and check the smallest index value. If it is smaller,
then, update it.
O(n) for the scan, and O(1) for the search if there is a direct
association between the code and the array index where it's foundState
is stored. HTH.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to