Before revision:  We give a faster algorithm  that runs in time O(n\log n).
After revision:  We give a faster algorithm for this problem that runs in time O(n\log n).