162. Reverse a Stack
Core1000 ms256 MBSolved by 0%
Read n values pushed onto a stack in the order given, reverse the stack,
then print it from TOP to bottom.
Pushing 1 2 3 leaves 3 on top. After reversing, 1 is on top, so the output is 1 2 3.
Use one extra stack. That is all you need.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers, pushed onto the stack in that order, so the LAST value given ends up on top.
Output
Print the reversed stack from TOP to bottom on one line, separated by single spaces.
Input3
1 2 3
Output1 2 3
Notereverses a three-value stack
Input1
7
Output7
Noteis a single value, where reversing changes nothing
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.