hmm... basically two strings are equal if the first 1/3 of one string is equal to the first portion of the other string?
This is what I suggest:
1. Sort of the array of strings.
2. Place the first string in the array of unique strings.
3. Consider 1/3 of the first string. Loop over the rest of the array, attempting to match as many characters as there are in this string under consideration.
4. If a match fails, add the string that caused the failure to the array of uniques. Place 1/3 of this string as the string under consideration, then continue the looping.
$array = array(/* ... */);
sort($array);
$uniques = array($array[0]);
$len = (int)(strlen($array[0]) / 3);
$str = substr($array[0], 0, $len);
foreach ($array as $value) {
if ($str != substr($value, 0, $len)) {
$uniques[] = $value;
$len = (int)(strlen($value) / 3);
$str = substr($value, 0, $len);
}
}
$array = $uniques;
This algorithm only makes a single pass through the array, so informally I would say its complexity should be equivalent to the sort. This is likely to be O(n log n), which is better than the O(n**2) complexity of bradgrafelman's algorithm.
EDIT:
My implementation has a bug for strings of length less than 3. However, the original formulation of the problem makes no provision for strings where 1/3 of the string length can be truncated to 0.