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