Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: The array [2, 4, 3, 1, 6, 5] is partitioned into the largest possible number of consecutive chunks such that after sorting each chunk independently, the whole array becomes sorted. How many chunks are there?

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

Correct answer: B. 2

A chunk boundary is valid after position i when the maximum of the prefix equals i + 1 (the prefix holds exactly the values 1 to i + 1). Here the boundaries fall after positions 4 and 6, giving two chunks.

More Coding Interview Problems questions

Exams that ask this topic