Baseline Recursion · Get Strong Hold O(n^2) — each of the n held elements sinks through up to n items · O(n) recursion stack
A courthouse clerk handles a single spring-loaded tray of case files that only allows the top file to be touched, and the newest case must end up on top instead of the oldest. The clerk may hold exactly one file in hand at a time and use only the tray's own push/pop action — no side tables. The call stack itself becomes the clerk's memory: hold the top file, reverse the rest of the tray, then push the held file all the way down to the bottom.
Input: An array stack representing the tray from bottom to top (the last element is the top).
Output: The array after the stack is reversed in place.
1 <= N <= 10^4-10^9 <= stack[i] <= 10^9Input: {"stack":[1,2,3,4,5]}
Output: [5,4,3,2,1]
Each popped top is sunk to the bottom of the shrinking tray, so the oldest file ends up on top.
Input: {"stack":[7,9]}
Output: [9,7]
Two files: the top (9) is held, the single-file remainder is trivially reversed, and 9 sinks to the bottom.