Pregunta de entrevista de Amazon

Problem on Monotonic Stack, and Binary Search Tree