We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
not optimal but still O(h), I simply brute forced and found both the parents and searched the common one.
let's be honest, are you really able to analyse the three cases and produce the optimal code on the spot? We are software engineers not mathematicians. For me this is like we can memorise and use (phi^n - (1-phi)^n)/sqrt(5) to find fib(n), but we would rather use dynamic programming to bruteforce!
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
not optimal but still O(h), I simply brute forced and found both the parents and searched the common one.
let's be honest, are you really able to analyse the three cases and produce the optimal code on the spot? We are software engineers not mathematicians. For me this is like we can memorise and use (phi^n - (1-phi)^n)/sqrt(5) to find fib(n), but we would rather use dynamic programming to bruteforce!