Sort Stack Recursively

Given an array representing a stack where the last element is the top of the stack, sort the stack so that the largest elements end up on top using only recursion. Do not use any explicit auxiliary data structures such as another array, stack, queue, or heap for sorting. The recursion call stack is allowed.

Return the sorted stack as an array in the same representation, with the top of the stack at the end.

Examples
Input: [3,1,2]
Output: [1,2,3]
Hints

Sort Stack Recursively

Given an array representing a stack where the **last element** is the **top** of the stack, sort the stack so that the largest elements end up on top using only recursion. Do not use any explicit auxiliary data structures such as another array, stack, queue, or heap for sorting. The recursion call stack is allowed.