Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
A staircase has 10 steps. You climb 1, 2 or 3 steps at a time but may never land on step 4 or step 7. Starting at step 0, how many different sequences of moves reach step 10?
- A. 274
- B. 106
- C. 42
- D. 48
Correct answer: C. 42
Set the count of every forbidden landing step to zero and use the tribonacci-style recurrence for the rest. Forbidding only the step itself without zeroing the count lets the sequences pass through it. Ignoring the restriction entirely gives the largest count.
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
- How many sequences of length 4 with entries from {1, 2, 3} are non-decreasing (each entry is at least the one before it)?
- A frog at position 0 wants to land exactly on position 17. Each jump has length 3, 5 or 7. What is the minimum number of jumps needed, or…
- How many binary strings of length 8 have every maximal run of equal digits of length at least 2?
- How many contiguous subarrays of [1, 2, 1, 3, 4, 2, 5] of length at least 2 consist of pairwise distinct values?
- For the array [7, 3, 9, 3, 5, 9, 1, 7], what is the maximum value of (j − i) over pairs of positions i < j with a[i] = a[j]?
- What is the length of the longest contiguous block of [2, 3, 5, 4, 6, 7, 8, 1, 2, 3] in which every element is strictly larger than the…