O(N) solution