Mid/SeniorArray

Partition Array into Disjoint Intervals

Given an integer array nums, partition it into two contiguous subarrays left and right so that:

  • Every element in left is less than or equal to every element in right.
  • left and right are non-empty.
  • left has the smallest possible size.

Return the length of left after such a partitioning.

Test cases are generated such that partitioning exists.

Example 1
Inputnums = [5,0,3,8,6]
Output3
The smallest valid partition is left = [5, 0, 3] and right = [8, 6].
Example 2
Inputnums = [1,1,1,0,6,12]
Output4
The smallest valid partition is left = [1, 1, 1, 0] and right = [6, 12].

Constraints

  • 2 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^6
  • There is at least one valid answer for the given input.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate