Pocket Gems interview question

Optimization on LCA