Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
How many index triples i < j < k in [3, 1, 4, 1, 5, 9, 2, 6] satisfy a[i] < a[j] < a[k] (strictly increasing)?
- A. 18
- B. 56
- C. 16
- D. 3
Correct answer: C. 16
For each middle index j, multiply the number of smaller values to its left by the number of larger values to its right; summing gives the count in O(n log n) with a BIT. Counting only triples of consecutive positions misses most of them.
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
- You stand on index 0 and must reach index 7. From index i you may move to any of the next 2 indices (i+1 or i+2). Landing on index j costs…
- What is the maximum product of THREE distinct elements of [-10, -3, 1, 5, 2, -8, 4] (chosen by position)?
- The substitutions-only distance (Hamming distance) between "karolin" and "kathrin" counts positions where the letters differ. What is that…
- What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two…
- Four houses are painted with one of 3 colours. Painting house i with colour c costs cost[i][c] = [[17, 2, 17], [16, 16, 5], [14, 3, 19]…
- Events are given as (start day, end day) inclusive: [(1, 2), (2, 3), (3, 4), (1, 2), (3, 5)]. You may attend at most one event per day…