Baseline Recursion · Get Strong Hold O(n^2) · O(n) recursion stack
A clinic's urgent-case tray only exposes its top folder, and the night shift must leave it ordered so the highest-priority case (largest number) sits on top. The same one-hand rule applies: hold one folder at a time, no side tables. The shift sorts the tray by always holding the top folder aside, sorting the remainder, then letting the held folder sink down to its correct slot from the top.
Input: An array stack representing the tray from bottom to top (the last element is the top).
Output: The array after the stack is sorted so the largest value is on top.
1 <= N <= 10^4-10^9 <= stack[i] <= 10^9Input: {"stack":[11,2,32,3,41]}
Output: [2,3,11,32,41]
Read bottom-to-top, the sorted tray ascends toward the top where 41 (the largest) sits.
Input: {"stack":[3,2,1]}
Output: [1,2,3]
Already in ascending order bottom-to-top, so sorting leaves the tray as it is.