FrontendX
Sort Stack Recursively
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Sort Stack
Recursively
Sort stack using recursion without extra data structures.
Examples
Example 1
Input:
[1,2,3]
Output:
[1,2,3]
Example 2
Input:
[1,2,3]
Output:
[1,2,3]
Hints
Hint 1
Pop all elements into an array.
Hint 2
Insert them back in sorted order using recursion.
Hint 3
Compare and push smaller elements first.
Sort Stack Recursively
Sort stack using recursion without extra data structures.