# Maximize The Topmost Element After K Moves: Explained
Maximize The Topmost Element After K Moves shows up often in coding rounds. Here is how I talk through it when the interviewer is watching.
## Key idea
A pile (array, index 0 is top). In one move remove the top or put a previously removed number back on top (you cannot put back if the pile is empty). After exactly k moves, maximize the top. Cases: if n == 1, the answer is -1 when k is odd (the only element is off the pile) else nums[0]. Otherwise you can expose any of the first min(k, n) elements by removing them, or put back the max of the first k-1 removed (when k-1 removals leave something to place). Take the best among those legal options; if k == 1 the answer is just nums[1] if it exists else -1.
## Steps to say out loud
1. Restate the input and the exact ask, and nail down constraints and overflow.
2. Name the pattern (binary search on the answer, monotonic stack or deque, interval / interval-DP, string hashing, graph traversal, or shortest paths) and why a nested scan or naive search fails.
3. Code it, then trace a short example plus one empty or already-solved edge case.
## Complexity
O(n).
## Common mistake
Ignoring the n == 1 parity case, or putting back an element after k removals rather than after k-1 (the put-back itself is the k-th move).
## Practice tip
Time yourself: two minutes to explain, ten to code, three to test edges. Disclosure: I work on Linkjob AI. I also keep a practice cheat sheet at AI job search and interview copilot.