#915

Partition Array into Disjoint Intervals

specialist · 880 · lc medium +31 · verified · 49.4% accepted · 1,766 likes · top 36%

Description

Partition the integer array nums into two non-empty contiguous parts — a prefix and a suffix — so that every value in the prefix is at most every value in the suffix. Return the length of the shortest such prefix.

Example 1:

Input: nums = [5,0,3,8,6]
Output: 3
Explanation: left = [5,0,3], right = [8,6]

Example 2:

Input: nums = [1,1,1,0,6,12]
Output: 4
Explanation: left = [1,1,1,0], right = [6,12]

Code

1
2
3