Pergunta de entrevista da empresa Amazon

binary expression tree part is tricky for me