Amadeus Interview Question

Easy Algorithm problem and optimization