Data Structures & AlgorithmsHardLeetCode-style · TCS NQT

How many contiguous subarrays (of length at least 2) of [1, 3, 4, 2, 5, 6, 8, 1] are strictly increasing?

  1. A. 12
  2. B. 5
  3. C. 9
  4. D. 7

Correct answer: C. 9

In a maximal increasing run of length L there are L(L−1)/2 increasing subarrays of length at least 2. Summing that over the runs gives the total. Counting only the maximal runs ignores all their sub-runs.

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

Exams that ask this topic