Amadeus interview question

problem solving like arrays manipulations by efficiency