RailYatri interview question

Traversing array in different ways