Ryanair Interview Question

solve a problem on hackerrank "Easy one"