Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

How many non-empty substrings of "aabcab" are already in non-decreasing (sorted) order?

  1. A. 13
  2. B. 10
  3. C. 21
  4. D. 6

Correct answer: A. 13

Maximal non-decreasing runs are 'aabc' and 'ab', giving 4·5/2 + 2·3/2 = 10 + 3 = 13 substrings. Requiring strictly increasing order breaks 'aa' and gives 10, 21 counts every substring and 6 only the single letters.

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

Exams that ask this topic