Amazon interview question

a coding problem on (monotonic) stack