Dsa
Stack
Warm-up
Sort Stack
You are given a stack of integers. You need to sort the stack such that the smallest integers are on the top. You should not use any other data structure except for the given stack, and you can use a temporary stack, if needed.
Input Format:
A space-separated string of integers representing the stack.
Output Format:
Output the sorted stack as a space-separated string.
Example:
Input:
3 2 5 1 4
Output:
1 2 3 4 5
Key concepts
stacksortingalgorithm
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now