Close
Topic list
Sort Stack
EASY
20 mins
Stacks & Queues
Topics (Covered in this problem)
Problem solved
Skill meter
Stacks & Queues
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Sort Stack

Contributed by
Prateek_18cb
Easy
0/40
Avg time to solve 20 mins
Success Rate 80 %
Share

## Problem Statement

#### You are given a stack ‘S’. Your task is to sort the sack recursively.

##### Note:
``````Looping through the stack is not allowed.
You need to return a stack that is sorted in descending order.
``````
##### For example:
``````Given stack S = 1 3 2
The output will be 3 2 1 since it is the sorted order.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
4
1 0 0 2
3
2 4 2
``````
##### Sample Output 1 :
``````2 1 0 0
4 4 2
``````
##### Explanation of the Sample Input 1:
``````For the first test case:
For the given stack, the resultant sorted stack would be 0 0 1 2.

For the second test case:
For the given stack, the resulting sorted stack would be 2 2 4.
``````
##### Sample Input 2 :
``````2
4
1 2 3 4
3
5 1 2
``````
##### Sample Output 2 :
``````4 3 2 1
5 2 1
``````
Auto
Console