removed the duplicate characters from a string using constant memory