Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement
In how many ways can the integer 10 be written as a sum of AT MOST 3 positive integers, where order does not matter (for example 10 = 7 + 2 + 1 = 2 + 7 + 1 is one way)?
- A. 14
- B. 8
- C. 6
- D. 23
Correct answer: A. 14
By conjugation (swap rows and columns of the Young diagram), partitions into at most 3 parts equal partitions into parts of size at most 3, counted by p(n, k) = p(n, k−1) + p(n−k, k). Counting exactly 3 parts, or allowing up to 4, gives a neighbouring 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
- From [1, 2, 3, 4, 6, 8, 12, 16, 18, 24, 36], choose the largest subset in which every pair of elements (the smaller divides the larger)…
- What is the largest XOR value obtainable as the XOR of a non-empty contiguous subarray of [8, 1, 2, 12, 7, 6]?
- What is the length of the longest arithmetic subsequence (equal consecutive differences, chosen by index) of [3, 6, 9, 12, 5, 10, 15, 20…
- Delete at most ONE element from [1, 3, 2, 5, 4, 6, 9, 7, 8] (or none). What is the length of the longest strictly increasing subsequence…
- From the array [5, 1, 8, 2, 9, 3, 7, 4], choose exactly 3 elements (by index) so that no two chosen indices are adjacent, and maximise…
- How many inversions does the array [2, 4, 1, 3, 5] have? An inversion is a pair of positions i < j with a[i] > a[j].