Data Structures & AlgorithmsHard
For [2, 1, 3, 5, 4, 6, 8, 7, 9], how many indices i with 1 ≤ i ≤ n−2 satisfy: every element before i is strictly less than a[i], and every element after i is strictly greater than a[i]?
- A. 4
- B. 2
- C. 7
- D. 3
Correct answer: B. 2
The condition needs the prefix maximum below a[i] and the suffix minimum above a[i]. Checking only one side, or relaxing both to ≤, changes which indices qualify.
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
- How many split points p with 1 ≤ p ≤ n−1 divide [1, 2, 2, 3, 2, 4, 5] into a left part and a right part such that every element of the…
- What is the length of the longest contiguous subarray of [4, 6, 5, 8, 9, 7, 10, 3] in which (maximum − minimum) ≤ 2?
- Choose a subsequence (elements need not be adjacent, but keep their original order) of [1, 9, 3, 4, 8, 2, 10, 5] of largest size such that…
- A string of length 4 is drawn from the alphabet {(, ), }. Each may be read as '(', as ')', or as the empty string. How many such strings…
- A linked list has nodes numbered 0 to 9 in order, and node 9's next pointer returns to node 3. Two pointers start at node 0: slow moves…
- In the sorted array [1, 1, 2, 2, 3, 4, 4, 5], how many different VALUE pairs {x, y} with x < y satisfy x + y = 6? (Repeated copies of a…