Amazon Interview Question

A Dynamic programming and stack problem.