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).

  1. A. 4
  2. B. 3
  3. C. 6
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic