Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many index pairs i < j in [1, 2, 3, 2, 1, 4] have a[i] + a[j] equal to 3 or to 6?
- A. 7
- B. {C+5}
- C. 9
- D. 6
Correct answer: D. 6
Pairs summing to 3 are 1 with 2, and pairs summing to 6 are 2 with 4 or 3 with 3 (requiring two 3s, which the array lacks). Hashing the complements counts each pair once.
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 cells are visited when a robot starts at (0, 0) and makes the moves R, U, R, D, L, U, U (R: x+1, L: x-1, U: y+1, D…
- What is the smallest positive integer that is divisible by every integer from 1 to 12 and is also a perfect square?
- A string is compared to a pattern by repeatedly rotating its first character to the end. How many distinct rotations of abab exist…
- What is the length of the longest substring of abcabdabcd that contains at most two distinct characters?
- How many pairs of distinct positions (i, j) with i < j in the string abcdcba satisfy s[i] = s[j]?
- In the sequence of queue operations enqueue 5, enqueue 3, dequeue, enqueue 8, dequeue, dequeue, enqueue 1, what is the value at the front…