Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many subarrays [i..j] of [3, 1, 4, 1, 5] have their first element strictly greater than every other element of the subarray?
- A. 15
- B. 2
- C. 5
- D. 7
Correct answer: D. 7
For each start the valid ends form a prefix: 3 gives [3], [3,1]; 1 gives [1]; 4 gives [4], [4,1]; then [1] and [5], total 7. Excluding singletons gives 2, counting only singletons 5, and 15 every subarray.
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 smallest positive integer x such that x(x+1)(x+2)/6 is at least 100?
- What is the maximum number of pairwise disjoint non-empty contiguous subarrays of [1, -1, 2, -2, 3, -3, 4] that each have sum zero?
- How many entries of [7, 8, 11, 16, 15, 3] have the largest number of 1-bits in the array?
- Sort all suffixes of "banana" lexicographically. What is the sum of the lengths of the longest common prefixes of each pair of adjacent…
- How many distinct substrings of length 4 does "abcabcabca" contain?
- How many proper borders (non-empty proper prefixes that are also suffixes) does "abaabaaba" have?