Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many index pairs i < j of [1, 2, 4, 6, 7, 9] have a sum strictly between 5 and 10?
- A. 6
- B. 7
- C. 8
- D. 5
Correct answer: D. 5
Count pairs with sum at most 9 and subtract those with sum at most 5, or check each pair directly. The bounds 5 and 10 are both excluded.
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 index pairs i < j in [2, 5, 3, 4, 1] satisfy a[i] < a[j] and every element strictly between i and j is at most a[j]?
- What is the smallest integer k such that 3k is at least every element of [5, 10, 14, 17]?
- What is the length of the longest contiguous substring of "bbacbbcab" containing at most one letter 'a'?
- What is the sum of a XOR (a >> 1) over a = 5, 8 and 13 (where >> is a right shift by one bit)?
- How many index pairs i < j in [2, 5, 4, 10, 3, 15] have a product that is a multiple of 10?
- With weight limit 15, what is the maximum number of items from [5, 3, 8, 2, 7, 4] you can carry (choose any subset)?