Amazon interview question

Problem on Monotonic Stack, and Binary Search Tree