Amazon Interview Question

Problem on Monotonic Stack, and Binary Search Tree