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)?

  1. A. 18
  2. B. 56
  3. C. 16
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic