Data Structures & AlgorithmsVery hard

How many contiguous subarrays of [1, 2, 3, 1, 2, 4, 5, 0, 6] are strictly increasing and have length at least 2?

  1. A. 19
  2. B. 3
  3. C. 10
  4. D. 20

Correct answer: C. 10

Split the array into maximal strictly increasing runs of length L; each run gives C(L,2) subarrays of length at least 2. Including singletons gives L(L+1)/2, while counting runs or ordered pairs gives other numbers.

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

Exams that ask this topic