Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
How many adjacent positions in [3, 9, 4, 7, 1] have a[i] > a[i+1]?
- A. 2
- B. 3
- C. 1
- D. 0
Correct answer: A. 2
Scan adjacent pairs and count the strict descents. Inversions over all pairs are a different measure, and a sorted run has zero descents.
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 minimum number of characters that must be inserted at the front of "abcdc" to make it a palindrome?
- Remove exactly one element from [5, -4, 3, -7, 2], then take the maximum product of two distinct remaining elements. What is that maximum…
- How many starting positions in "abcbabcab" match the pattern "abc" with exactly one mismatched character?
- How many substrings of length 2 of "abcba" read the same forwards and backwards?
- A histogram has bar heights [2, 1, 5, 6, 2, 3, 4, 1] (each bar has width 1). What is the area of the largest rectangle that fits entirely…
- What is the sum of the minimum element over every contiguous subarray of [3, 1, 2, 4, 1]? (Every subarray counts, including repeated…