Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] = 10?
- A. 4
- B. 5
- C. 3
- D. 7
Correct answer: C. 3
Fix the smallest index and look for pairs in the rest that sum to the remaining value; the triples are ordered by index, so each set counts 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 values in [4, 4, 5, 6, 6, 7, 8] occur exactly once in the array?
- How many contiguous subarrays of [1, 1, 2, 2, 2, 3] contain only one distinct value?
- How many index pairs i < j in [1, 4, 7, 2, 5, 8] satisfy that a[i] - a[j] is divisible by 3?
- How many substrings of the string aaabaa consist only of the letter a?
- What is the length of the longest proper prefix of abcab that is also a suffix of abcab (the border)?
- What is the number of occurrences of the pattern abab in the string ababababab, counting overlapping matches?