# stacks easy

Reverse the Train

The train enters the dead-end tunnel engine-first β€” it can only come out reversed. πŸš‚

You get the cars in order. Run them through a stack to reverse them, and print the new order, comma-separated. (You reversed a list with end-swaps in Sorting β€” this is reversal, approach two!)

Example:

Input: cars = ["engine", "coal", "mail", "caboose"] Output: caboose,mail,coal,engine

Pushing every car into the tunnel and popping them back out flips the order β€” caboose, pushed in last, comes out first.

πŸ’‘ need a hint?

stk-reverse-train.pyπŸ”’ given lines are locked β€” write your code in between
loading...