Data Structures & AlgorithmsHardTCS NQT · Infosys
How many index pairs i < j in [1, 2, 3, 4, 5, 6, 7, 8] have equal parity and a[i] + a[j] <= 10?
- A. 10
- B. 11
- C. 13
- D. 9
Correct answer: D. 9
Group odds and evens separately; within each group count the pairs whose sum is at most 10, using sorting and two pointers.
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 aabbbcca in which every letter occurs at most twice?
- How many palindromic substrings of length 3 or more does racecar contain (counted by position)?
- How many distinct rotations does the string aabaab have (including itself)?
- What is the sum of all positive divisors of 28, a perfect number?
- How many integers in [1, 100] have exactly two distinct prime factors (counted without multiplicity)?
- What is the digital root of 98765 (repeatedly sum the digits until one digit remains)?