Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many ordered sequences of positive integers, each at most 3 and with at least two terms, sum to 6?
- A. 25
- B. 24
- C. 22
- D. 13
Correct answer: B. 24
Count ordered compositions with parts in {1, 2, 3} via dp[i] = dp[i−1] + dp[i−2] + dp[i−3], then subtract the one-part composition (the single term n, valid only when n ≤ 3). Forgetting to remove the one-part case overcounts.
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
- For the array [3, 5, 6, 1], compute the XOR of every non-empty contiguous subarray and add all these XOR values together. What is the total?
- How many non-empty contiguous subarrays of [2, 4, 6, 1, 3, 1, 2, 4] have a bitwise XOR equal to 0?
- What is the length of the shortest contiguous substring of "xaybzcabbc" that contains "abc" as a SUBSEQUENCE (the letters appear in order…
- How many index triples i < j < k in "abacbab" spell a palindrome of length 3, meaning s[i] = s[k]? (The middle letter is unrestricted.)
- What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?
- Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins…