Reverse a Stack using Recursion
Medium

Problem Statement

Write a program to reverse a stack using recursion. You are not allowed to use any extra space other than the internal stack space used by recursion.

Examples

1Example 1
Input:
{ "stack": [ 1, 2, 3, 4, 5 ] }
Output:
[ 5, 4, 3, 2, 1 ]
2Example 2
Input:
{ "stack": [ 10, 20, 30 ] }
Output:
[ 30, 20, 10 ]
3Example 3
Input:
{ "stack": [ 5 ] }
Output:
[ 5 ]
Loading...

Sign in to Run Code and Submit