An efficient approach to find the above problem. https://github.com/tranquilshore/CS_learn/blob/master/Binary%20Tree/lca.py
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.