Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many index pairs i < j in [3, 4, 4, 5, 7, 6] have values that differ by exactly 1?
- A. 7
- B. 8
- C. 10
- D. 6
Correct answer: D. 6
Count the pairs (3,4) twice, (4,5) twice, (5,6) once and (6,7) once; the value 7 pairs with 6 at a later index, which is counted as a separate 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
- What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3] that contains at most two distinct values?
- How many adjacent position pairs in the string abbaabab are equal to ab or ba (overlapping adjacent pairs counted)?
- What is the lexicographically smallest rotation of the string bca?
- What is the sum of all integers x in [1, 50] that are divisible by 4 or by 6?
- How many positive divisors of 360 are odd?
- What is the largest n such that 1 + 2 + ... + n does not exceed 1000?