Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement
How many subsets of the set {1, 2, ..., 10} (the empty set included) contain no two consecutive integers?
- A. 144
- B. 143
- C. 1024
- D. 92
Correct answer: A. 144
A bitmask with no two adjacent set bits can be counted by the recurrence a(n) = a(n−1) + a(n−2), which is Fibonacci-like. The empty set is one valid choice, so it is included in the 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
- In how many ways can 6 distinct people be divided into 3 unordered pairs (every person is in exactly one pair, and the pairs are not…
- Items are given as (weight1, weight2, value): [(2, 3, 4), (3, 4, 5), (4, 6, 2), (1, 1, 1), (5, 7, 8)]. Each item can be used once. You…
- How many ways can the six numbers [1, 2, 3, 4, 5, 6] be assigned to three labelled groups (group A, group B, group C), each number going…
- From the numbers [1, 2, 3, 5, 6, 8, 9, 10], what is the size of the largest subset in which any two chosen numbers differ by at least 2?
- Starting at index 0 of the array [4, 8, 5, 2, 25], repeatedly jump to the next strictly greater element (a monotonic stack gives these…
- What is the sum of the stock span values for prices [100, 80, 60, 70, 60, 75, 85]? The span of day i is the number of consecutive days…