mediumArrayDynamic Programming 0 views
Check if There is a Valid Partition For The Array
You are given a 0-indexed integer array nums.
You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.
We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions:
Return true if the array has at least one valid partition. Otherwise, return false.
Example 1
Input: nums = [4,4,4,5,6]
Output: true
Explanation: The array can be partitioned into the subarrays [4,4] and [4,5,6]. This partition is valid, so we return true.
Example 2
Input: nums = [1,1,1,2]
Output: false
Explanation: There is no valid partition for this array.
Constraints
- 2 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^6
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.