And now, the algorithm in O(n)