Data Structures & AlgorithmsHard

For 3 9 1 7 2 8 4, split the array into a non-empty left part and a non-empty right part at some position p. What is the LARGEST possible value of (maximum of the left part) − (minimum of the right part)?

  1. A. 7
  2. B. 8
  3. C. 2
  4. D. 9

Correct answer: B. 8

For each split, the left maximum is a running prefix maximum and the right minimum is a suffix minimum, both computable in one pass. Using the global spread, subtracting one, or taking the worst split answers different questions.

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

Exams that ask this topic