Reverse a Stack using Recursion
Medium

Problem Statement

Given a stack, reverse it 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": [ 3, 2, 1, 4 ] }
Output:
[ 4, 1, 2, 3 ]
3Example 3
Input:
{ "stack": [ 1 ] }
Output:
[ 1 ]
Loading...

Sign in to Run Code and Submit