Problem · Array

Minimum Number of Split Operations to Make Array Sorted

Learn this problem
MediumGoogleFULLTIMEONSITE INTERVIEW
See Google hiring insights

Problem statement

You're optimizing video chunks for streaming. Each chunk has a size represented in a 0-indexed array nums. To ensure smooth playback, chunk sizes must be in non-decreasing order.

You can split any chunk into two smaller chunks whose sizes add up to the original.

For example, if nums = [10,5,8], you can split 10 into [4,6] making it [4,6,5,8].

Return the minimum number of split operations needed to make the array sorted in non-decreasing order.

The candidate was able to come up with an O(n^2) solution within 15 minutes but was asked to improve it to O(n), which they couldn't achieve.

Function

minSplitOperations(nums: int[]) → int

Examples

Example 1

nums = [10, 5, 8]return = 1
:) The output may be 1. If anything is found to be wrong, I am more than happy to make modifications.

More Google problems

drafts saved locally
public int minSplitOperations(int[] nums) {
  // write your code here
}
nums[10, 5, 8]
expected1
checking account