Data Structures & AlgorithmsVery hardTCS NQT · Infosys
How many index pairs i < j in [1, 3, 5, 7, 9, 4] have |a[i] - a[j]| = 2?
- A. 5
- B. 4
- C. 6
- D. 8
Correct answer: B. 4
The pairs with difference 2 are (1,3), (3,5), (5,7) and (7,9). The value 4 has neither 2 nor 6 in the array, so it adds no pair.
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 appear among the XORs of all non-empty contiguous subarrays of [1, 2, 3]?
- How many windows of length 3 in the string abaaabaa are anagrams of aab (same letters with the same counts)?
- What is the length of the longest substring of aabaaccaa that contains at most two letters 'a'?
- How many palindromic substrings (counted by position) does the string abbaabba contain?
- How many distinct palindromic substrings does the string aabaa contain?
- What is the smallest integer x greater than 100 with x congruent to 3 modulo 7 and x congruent to 5 modulo 11?