Data Structures & AlgorithmsHard

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 left part is ≤ every element of the right part?

  1. A. 3
  2. B. 6
  3. C. 5
  4. D. 4

Correct answer: C. 5

A split is good when max(left) ≤ min(right), which is a comparison of two running extremes. Using strict < discards equal boundary values, while reversing the comparison counts the bad splits instead.

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

Exams that ask this topic