Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
How many non-empty substrings of "aabcab" are already in non-decreasing (sorted) order?
- A. 13
- B. 10
- C. 21
- 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.
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
- What is the sum of the maxima of every window of size 2 in [9, 4, 7, 1, 8]?
- How many contiguous subarrays of [1, 2, 3, 4, 6, 1] have a product exactly 12?
- Starting at index 0 of [1, 2, 1, 1, 1], each a[i] is the maximum forward jump. What is the minimum number of jumps needed to reach the…
- What is the length of the longest contiguous substring of "([)][]()[[]]" that is a balanced bracket sequence, where '(' must close with…
- How many contiguous substrings of "(()())(())((()))" are balanced round-bracket sequences whose maximum nesting depth is at most 2?
- What is the length of the longest contiguous substring of "xxyxyyxyxxy" in which the number of 'x' letters is at most the number of 'y'…