Data Structures & AlgorithmsHardTCS NQT · Accenture
For the array [1, 2, 2, 3], how many distinct sums a[i] + a[j] are formed by pairs with i not equal to j (ordered pairs)?
- A. 4
- B. 3
- C. 5
- D. 7
Correct answer: B. 3
The distinct sums are 3 (from 1 + 2), 4 (from 1 + 3 and 2 + 2) and 5 (from 2 + 3). Counting every ordered pair instead gives a larger number.
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 distinct values in [1, 1, 2, 2, 2, 3, 4, 4] occur more than one third of the time (count times 3 greater than n)?
- How many substrings of the string aabbaabb have an equal number of letters a and b?
- What is the length of the longest prefix of abacaba that is a palindrome?
- What is the sum of floor(i / 2) for i = 1 to 10?
- What is the smallest positive integer that has exactly 6 positive divisors?
- How many integers n in [1, 100] have both n and n + 2 prime?