Data Structures & AlgorithmsHardCodeforces Div2 D · LeetCode-style

You stand on index 0 and must reach index 7. From index i you may move to any of the next 2 indices (i+1 or i+2). Landing on index j costs c[j], and the cost of index 0 is c[0]. What is the minimum total cost of a path?

  1. A. 17
  2. B. 11
  3. C. 18
  4. D. 15

Correct answer: D. 15

dp[i] = c[i] + min(dp[j]) over the last k reachable indices. A monotone-deque or a sorted structure keeps the window minimum fast, but a plain sum over alternate positions picks a fixed pattern that need not be cheapest.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic