Amazon interview question

A Dynamic programming and stack problem.