Data Structures & AlgorithmsModerateGATE CS · CAT · MBA placement
In how many ways can you choose 3 indices from the 9 positions 1 to 9 so that no two chosen positions are adjacent (consecutive integers)?
- A. 84
- B. 35
- C. 41
- D. 36
Correct answer: B. 35
Pick k non-adjacent positions from n by placing the chosen ones into n − k + 1 gaps: the count is C(n − k + 1, k). Choosing any 3 positions out of 9 without the adjacency rule gives C(9, 3).
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
- What is the length of the longest contiguous subarray of [4, 7, 5, 6, 8, 9, 7, 6, 3, 4] in which the largest value minus the smallest…
- How many contiguous subarrays of [3, 1, 3, 2, 3, 1] have their maximum value occurring EXACTLY twice inside the subarray?
- How many strings of length 5 over the alphabet {a, b, c} contain no two adjacent equal letters when the letter is a or b (two adjacent c's…
- How many binary strings of length 6 have exactly 4 maximal runs (blocks of equal consecutive digits)?
- How many unordered pairs of different positions in [3, 8, 2, 9, 5, 4] have a product at most 24?
- What is the smallest period of the string "abaababaab"? The smallest period p is the least p > 0 such that s[i] = s[i + p] for every valid…