Data Structures & AlgorithmsHardCodeforces Div2 D · GATE CS
Count the index paths from position 0 to position 6 in the array [1, 3, 2, 4, 6, 5, 7] where each move goes from index i to a LATER index j with 1 ≤ a[j] − a[i] ≤ 2. How many such paths exist?
- A. 8
- B. 0
- C. 5
- D. 13
Correct answer: C. 5
A DAG path-count DP: cnt[j] = Σ cnt[i] over earlier i with the value difference in [1, d]. Counting only the adjacent moves (j = i + 1) is a much smaller set of paths.
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
- A binary partition of 20 is a way to write 20 as a sum of powers of two (1, 2, 4, 8, ...), where order does not matter and repeats are…
- On a 1 × 9 strip of cells, you place 3 non-overlapping dominoes, each covering two adjacent cells. Two dominoes may not share a cell. How…
- How many binary strings of length 9 contain exactly 4 ones and no run of three or more consecutive 0s?
- Closed integer intervals are [(1, 4), (2, 3), (5, 7), (4, 6), (8, 9), (7, 8)]. How many unordered pairs of intervals share at least one…
- The numbers [1, 6, 3, 8, 4] can be arranged in any order in a row. Maximise the sum of absolute differences between neighbouring numbers…
- Using only swaps of ADJACENT elements, what is the minimum number of swaps needed to turn [1, 2, 3, 2, 1, 3, 3] into a palindrome? (It is…