Data Structures & AlgorithmsModerate
In 3 1 4 1 5 9 2 6 5 3 5 8, count how many positions hold a NEW strict prefix maximum (the element is strictly greater than every element before it; the first element counts as new).
- A. 4
- B. 3
- C. 6
- D. 5
Correct answer: A. 4
Keep the running maximum and count strict increases of it; the first element always starts a new maximum. Non-strict comparisons, adjacent increases, or excluding the first element each give different counts.
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 DISTINCT strings are produced by all cyclic rotations of "abcabc" (including the identity rotation)?
- How many inversions (pairs i < j with A[i] > A[j]) does 4 5 6 1 2 3 contain?
- Records are (letter, number): (b, 2), (a, 1), (c, 2), (a, 2), (b, 1), (c, 1). Apply a stable sort by LETTER first, then a stable sort by…
- For every window of length 3 in 9 2 7 4 1 8, sort the window and take its MIDDLE value. What is the largest of these middle values?
- Two sorted lists 1 4 6 9 and 2 3 7 8 10 are merged with the standard two-pointer merge (take the smaller head; on a tie take from the…
- In the sorted array 1 2 2 2 3 5 5 8, what is the 0-based index of the FIRST occurrence of the value 5 (the leftmost position where 5…