This is interval DP once you see it, but if you don't immediately recognize the pattern you can waste a lot of time trying to think about it as a greedy problem.
Recognize this as a dynamic programming problem where you need to minimize the maximum cost across all possible target numbers. Define dp[i][j] as the minimum cost to guarantee a win when the number is in range [i, j], and derive the recurrence by considering each possible guess k and taking the worst-case cost. Optimize the O(n^3) DP to O(n^2) using monotonicity or Knuth's optimization if needed.
Pro tip: After presenting the DP, mention that the optimal first guess is often around n/√2 or derived from the recurrence, and that the problem is equivalent to finding the optimal binary search tree with weights equal to the guessed numbers. This shows depth and connects to classic algorithms.
Confirm that the cost is the sum of all wrong guesses, and that you need the minimum total cost that guarantees a win regardless of the chosen number. Ask if n is given and if there are constraints on n.
Let dp[i][j] be the minimum cost to guarantee a win for a number in the range [i, j]. The base case is dp[i][i] = 0 (no cost if only one number, you guess it correctly).
For each possible guess k in [i, j], the cost is k + max(dp[i][k-1], dp[k+1][j]). The answer for range [i, j] is the minimum over k of this expression. Explain why we take the max: because the adversary chooses the direction that maximizes cost.
Naively, the DP takes O(n^3) time. Mention that it can be optimized to O(n^2) using Knuth's optimization or by observing monotonicity of the optimal guess. For small n, O(n^3) is acceptable.
The final answer is dp[1][n]. Optionally, discuss how to reconstruct the optimal guessing strategy.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.