text function lowestCommonAncestor(root, p, q): current = root while current != null: if p.val < current.val and q.val < current.val: current = current.left else if p.val > current.val and q.val > current.val: current = current.right else: return current return null Time complexity: where is the tree height. Space complexity: for the iterative version.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/trees-bst/lowest-common-ancestor-of-bst-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████████████████████████████████