Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement
How many DIFFERENT values can the sum of three distinct integers chosen from 1 to 9 take?
- A. 19
- B. 84
- C. 21
- D. 18
Correct answer: A. 19
Every sum between the minimum 1 + 2 + 3 = 6 and the maximum 7 + 8 + 9 = 24 is achievable with distinct triples, so the count is the number of integers in that range. Counting the triples (C(9, 3) = 84) counts repeated sums many times.
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 substring of "aebcdiouxyab" in which the number of vowels (a, e, i, o, u) equals the number of non-vowels?
- How many index pairs (i < j) in [4, 9, 1, 7, 12, 5, 8, 3] satisfy a[i] − a[j] = 3 (exactly 3, in this order)?
- Starting from the number 1, each operation either doubles the current number or adds 1. What is the minimum number of operations needed to…
- How many pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?
- Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?
- What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?