Amadeus Interview Question

problem solving like arrays manipulations by efficiency