Data Structures & AlgorithmsVery hardTCS NQT · Infosys
How many index pairs i < j in the array [1, 3, 1, 2, 3, 3] have a[i] = a[j]?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
For each value with frequency f there are f(f-1)/2 equal pairs. The value 3 occurs three times, giving three pairs by itself.
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 sum of the XOR of every non-empty contiguous subarray of [1, 2, 3]?
- How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?
- How many ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j}…
- What is the length of the longest prefix of the string ababbaba that is itself a palindrome?
- An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?
- How many integers i with 1 <= i <= 50 have i i mod 10 = 9?