Check if it is Possible to Split Array - Problem
You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n arrays of size 1 by performing a series of steps.
An array is called good if:
- The length of the array is one, or
- The sum of the elements of the array is greater than or equal to
m.
In each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two arrays, if both resulting arrays are good.
Return true if you can split the given array into n arrays, otherwise return false.
Input & Output
Example 1 — Basic Splittable Case
$
Input:
nums = [2,1,2,6], m = 4
›
Output:
true
💡 Note:
We can split [2,1,2,6] → [2,1,2] and [6]. Both are good: [2,1,2] has sum 5 ≥ 4, and [6] has length 1. Continue splitting [2,1,2] until all elements are separated.
Example 2 — Non-splittable Case
$
Input:
nums = [2,1,1,1], m = 4
›
Output:
false
💡 Note:
No two adjacent elements sum to 4 or more: 2+1=3, 1+1=2, 1+1=2. We cannot split any subarray of length > 2 while keeping both parts good.
Example 3 — Small Array
$
Input:
nums = [1,1], m = 10
›
Output:
true
💡 Note:
Arrays of length ≤ 2 can always be split into individual elements since single elements are always considered good.
Constraints
- 1 ≤ nums.length ≤ 100
- 1 ≤ nums[i] ≤ 1000
- 1 ≤ m ≤ 200
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [2,1,2,6] with minimum sum threshold m=4
2
Strategy
Check if any adjacent pair sums ≥ m (enables splitting)
3
Result
Found 2+6=8 ≥ 4, so answer is true
Key Takeaway
🎯 Key Insight: We only need one adjacent pair summing ≥ m to enable complete splitting
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code