Amadeus interview question

Easy Algorithm problem and optimization