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?
- A. 3
- B. 2
- C. 1
- 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
- Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?
- Problem: The product 2^3 · 3^2 · 5^1 · 7^2 has how many positive divisors?
- Problem: For the array [1, 3, 5, 7, 9], how many subarrays have an average equal to 5?
- Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?
- Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the…
- Problem: The complete directed graph on 4 vertices has an arc in both directions between every pair of distinct vertices. How many…