Ryanair interview question

solve a problem on hackerrank "Easy one"