v1 time O(n) space O(log(n)) Accepted

worst case is O(n)

avg is O(log(n))