Added second implementation O(N)