Amazon Interview Question

binary expression tree part is tricky for me