Amazon interview question

binary expression tree part is tricky for me