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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution