FastPrepPartition Array into Disjoint Intervals

Partition Array into Disjoint Intervals

Bloomberg LP logoBloomberg LP● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Split nums into a nonempty left prefix and a nonempty right suffix so every value in the left part is less than or equal to every value in the right part.

Return the smallest possible length of the left part. A valid split is guaranteed.

Function

partitionDisjoint(nums: int[]) → int

Examples

Example 1

nums = [5,0,3,8,6]return = 3

The prefix [5,0,3] has maximum 5 and the suffix [8,6] has minimum 6.

Constraints

  • 2 <= nums.length <= 10^5.
  • Values fit in signed 32-bit integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int partitionDisjoint(int[] nums) {
  // Write your code here.
}
nums[5,0,3,8,6]
expected3
Checking account…