Got O(n) and O(n logn) implementations