
Glad you said you found it
I thought about it, came up with one of the n log(n) algorithms, but now don't feel obliged to type it up. :-)
Cheers,
Ben
About the use of language: it is impossible to sharpen a pencil with a blunt axe. It is equally vain to try to do it with ten blunt axes instead. -- Edsger W. Dijkstra