in reply to Recognizing duplicates

I'd use this function:

index(STRING, SUBSTRING, POSITION) -- Returns the position of the first occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the beginning of STRING

You'll be looking for the first occurrence of the CURRENT character in the string AFTER the current position. Any way you look at it, it is O(n^2) on the length of your string. At least this solution doesn't use additional memory like the solution with the hash.

Replies are listed 'Best First'.
Re^2: Recognizing duplicates
by Sartak (Hermit) on Oct 20, 2007 at 05:42 UTC
    Actually, the hash based solution is roughly O(length) time. It's (approximately) a constant amount of time to insert/index into the hash, and you only iterate over the string once.