Given a string *Str of ASCII characters, write the pseudo code to remove the duplicate elements present in them. For example, if the given string is “Potato”, then, the output has to be “Pota”. Additional constraint is, the algorithm has to be in-place.
I have written a program with bool array of 255 elements and keep their value to be false.while traversing the string i change their value to true to mark them as visited and in this way i have another string of unique values.In this way i am using constant space.Is there any better way of doing this.please suggest.
You used the words “another string”, so maybe, just maybe, you have 2 strings? The idea of in-place is that you do it in the same string. But maybe you just meant “another string contents”, so yes, then it’s fine. To clarify: you have the string given, and assign two pointers to the beginning of it, then advance your reader-pointer reading one char at a time, writing (and thus incrementing your writer-pointer) only if the char was not already in your 255-table.