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