Data Structures & AlgorithmsHard
How many subsequences of EXACTLY three elements of 6 10 15 4 9 (position subsets) have gcd equal to 1?
- A. 3
- B. 2
- C. 0
- D. 8
Correct answer: D. 8
The gcd of a triple is the gcd of the first two combined with the third; enumerate triples and test. Counting pairs, the complement, or testing only one element against the others each give other counts.
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 contiguous windows of length exactly 2 in 4 7 2 9 3 5 11 8 have BOTH values prime?
- Why does the two-transaction stock problem split the array at a point and solve each side independently?
- When the maximum and minimum must end at the two extremes by adjacent swaps, why can their costs interact?
- Why does 'maximum number of disjoint zero-sum blocks' use an interval DP over prefixes rather than a greedy scan?
- To count subarrays of length at least 2 with equal odd and even counts, why is the length-1 case excluded?
- Why is the minimum over all rotations of a permutation's inversion count achieved by a specific rotation that can be found in linear time?