Amazon interview question

Trees, graphs and dp, stack