Remove duplicate characters in a given string without using additional buffer