Sort a Stack using Recursion
Medium

Problem Statement

Given a stack, sort it in ascending order (with the smallest elements on top) using only recursion.

Examples

1Example 1
Input:
{ "stack": [ 5, 1, 0, 2, 4 ] }
Output:
[ 0, 1, 2, 4, 5 ]
2Example 2
Input:
{ "stack": [ 34, 3, 31, 98, 92, 23 ] }
Output:
[ 3, 23, 31, 34, 92, 98 ]
3Example 3
Input:
{ "stack": [ 1, 2, 3, 4, 5 ] }
Output:
[ 1, 2, 3, 4, 5 ]
Loading...

Sign in to Run Code and Submit