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