Loading...
Loading...
Loading...
A store prints its packing list in the order orders arrived, but the van is loaded last parcel first. Read the product codes and print them in reverse order, using a stack.
Example
Input
4 A12 B7 C3 D99
Output
D99 C3 B7 A12
The last code, D99, is printed first.
Try the problem first. Open one hint at a time.
Push every code on an ArrayDeque with push.
Then pop until the stack is empty: the last code pushed comes out first.
Join the popped codes with one space; do not print a space at the end.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor