Sort stack using another stack

Given a stack of integers A, sort it using another stack.

Return the array of integers after sorting the stack using another stack.



Input Format

The only argument given is the integer array A.

Output Format

Return the array of integers after sorting the stack using another stack.

Constraints

1 <= length of the array <= 5000
0 <= A[i] <= 10^9 

For Example

Input 1:
    A = [5, 4, 3, 2, 1]
Output 1:
    [1, 2, 3, 4, 5]

Input 2:
    A = [5, 17, 100, 11]
Output 2:
    [5, 11, 17, 100]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Sort  stack using  another stack on Interview Code Editor
Sign Up
to access hints and editorial solutions for Sort stack using another stack

Discussion


Loading...
Click here to start solving coding interview questions