Amadeus interview question

Code stack operations in real-time and optimize