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?
- A. 17
- B. 11
- C. 18
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum product of THREE distinct elements of [-10, -3, 1, 5, 2, -8, 4] (chosen by position)?
- The substitutions-only distance (Hamming distance) between "karolin" and "kathrin" counts positions where the letters differ. What is that…
- What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two…
- Four houses are painted with one of 3 colours. Painting house i with colour c costs cost[i][c] = [[17, 2, 17], [16, 16, 5], [14, 3, 19]…
- Events are given as (start day, end day) inclusive: [(1, 2), (2, 3), (3, 4), (1, 2), (3, 5)]. You may attend at most one event per day…
- Split "ababcbacadefegdehijhklij" into the maximum number of contiguous pieces so that each letter appears in at most one piece. What is…