Amazon Interview Question

a coding problem on (monotonic) stack