Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many ordered index pairs (i, j) in [1, 3, 4, 7, 10, 12, 15] satisfy a[j] - a[i] = 3?
- A. 5
- B. 4
- C. 3
- D. 2
Correct answer: B. 4
With distinct sorted values, each value v has at most one partner v + 3, so the count is the number of such matches. Checking membership with two pointers or a set gives the same total.
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 integers from 1 to 10000 inclusive are multiples of 7 whose decimal digit sum is exactly 7?
- For "aabaabaa", how many indices i >= 1 have Z-function value exactly 2?
- How many ordered pairs (a, b) of integers with a >= 2 and b >= 2 satisfy a b = 36?
- Moving one unit per step, what is the minimum total number of unit moves to make every element of [1, 2, 9, 10, 12] equal to a common…
- How many index triples i < j < k in [1, 2, 3, 4, 5, 6] satisfy a[i] + a[k] = 2 a[j]?
- What is the area of the largest rectangle under the histogram [3, 1, 3, 2, 2]?