Amazon interview question

DP on graphs and monotnic stack