Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional
How many index triples i < j < k satisfy a[i] + a[j] + a[k] <= 4 for a = [-4, -1, 0, 2, 3, 5]?
- A. 14
- B. 11
- C. 16
- D. 15
Correct answer: A. 14
Sorting then fixing the smallest index and using two pointers counts all triples in O(n^2). Checking sums only up to 3 or 5 shifts the count by one or two triples.
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 windows of length 3 in [1, 2, 3, 1, 2, 2, 4, 1, 3, 4] contain three pairwise distinct values?
- In the string "bbaacbbaaac", what is the length of the shortest contiguous substring that contains at least three letters 'a'?
- Piles of bananas are [3, 6, 7, 11] and you must finish all piles within 8 hours, eating at speed k bananas per hour (taking ceil(pile / k)…
- The array [7, 2, 5, 10, 8] is split into exactly 2 non-empty contiguous parts so that the largest part sum is as small as possible. What…
- How many non-empty contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 5 (including negative sums, which are divisible…
- An array of 6 zeros (indices 0 to 5) receives three range-add operations, each adding v to every index from l to r inclusive: (1,3,+2)…