SECTION 25 / 28

Search direct routes with direction and weekday

1 min read
On a route Bengaluru → Bhubaneswar → Kolkata, the same service can carry a forward query but not the reverse query.
On a route Bengaluru → Bhubaneswar → Kolkata, the same service can carry a forward query but not the reverse query.
REAL COURSE DATA · SORT, GROUP AND VERIFY

Search for a direct train in the correct direction

Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change. Keep track of which list level, field and position convention the procedure uses.

Matches = []
foreach Train in candidatesCallingAt(Source):
    i = positionOf(Source, Train.Stops)
    j = positionOf(Destination, Train.Stops)
    if i >= 0 AND j > i AND departureExistsAt(i):
        if requestedWeekday is a departure weekday at Source:
            Matches = Matches ++ [Train.Number]

The outer loop examines candidate trains; the inner scan examines their station lists. Source must occur before destination in that direction, and the train must depart from the source. Finding both names somewhere in a card is insufficient. A service arriving at its final station cannot carry a passenger onward on the same card.

In the verified subset, 02246 goes Bengaluru to Bhubaneswar: departure 11:00 on Day 1 and arrival 09:50 on Day 2, a duration of 22 h 50 min. It originates Monday, Tuesday, Thursday, Friday and Sunday. The Wednesday option therefore has no match for that query on this service.

Chennai-to-Ahmedabad has no matching direct train in the source discussion and our teaching subset. This is a scoped dataset result, not a claim about present-day rail services or every possible connection. A direct-route match also says nothing about seats, fares or real-time delays.

Try it yourself

If a train lists Destination before Source, does it answer the forward query?

Show explained answer

No. It is travelling in the wrong order for that trip.

Try it yourself

If you board at a Day 2 intermediate station, whose weekday must you check?

Show explained answer

The departure weekday at that source station, obtained by shifting the origin weekday by the appropriate journey-day offset.

Try it yourself

Does “no direct match in this subset” rule out a trip with a transfer?

Show explained answer

No. Direct services and connecting journeys are different search tasks.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑