Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many index pairs i < j of [1, 2, 5, 7, 10] have absolute difference at least 3?
- A. 6
- B. 2
- C. 5
- D. 8
Correct answer: D. 8
Of the 10 pairs, only (1,2), (5,7) are closer than 3, so 8 qualify; 'at least' keeps the pairs with difference exactly 3, (2,5) and (7,10). The strict version drops those and gives 6, checking only adjacent pairs gives 2, and 5 is the array length.
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
- Numbers 1, 2, 3, 4 are pushed in this order onto a stack. Can the pop sequence 3, 4, 2, 1 be produced?
- How many length-3 substrings of "abcabc" are rotations of "abc" (namely abc, bca or cab)?
- What is the sum of the decimal digits of 2^20?
- Among intervals [1,6], [4,9], [5,5], [2,8], [5,7], [3,6] that contain the point 5, what is the largest number that are pairwise disjoint…
- How many index pairs i < j in [2, 3, 4, 5, 8, 9] have an odd sum?
- How many integers from 1 to 999 inclusive have all decimal digits distinct?