add O(N) implementation