Answer: Robinhood OA Question 2024 September | Stack | on-campus

Answer · Posted Jun 2026

Solution: Min Stack — Dual Stack Approach Approach We maintain two stacks: mainStack: stores all elements as a normal stack. minStack: stores the current minimum at each state. Every time we push to mainStack, we also push min(val, minStack.peek()) to minStack. This way, minStack.peek() always reflects the minimum of all elements currently in mainStack. When we pop from mainStack, we also pop from minStack to keep them in sync. Algorithm Walkthrough push(val): Push val to mainStack. Push min(val, minStack.peek()) to ...

The full answer & interview discussion are available to premium members.

Log in Create a free account