Check if it is Possible to Split Array - Problem
Array Splitting Challenge

You're given an array nums of length n and an integer m. Your task is to determine whether you can completely break down this array into individual elements (arrays of size 1) through a series of strategic splits.

The Rules:
• An array is considered "good" if it has length 1 OR its sum ≥ m
• You can only split an array if BOTH resulting parts are "good"
• Keep splitting until you have n individual arrays

Goal: Return true if complete decomposition is possible, false otherwise.

This problem tests your understanding of dynamic programming and greedy algorithms - you need to find the optimal splitting strategy!

Input & Output

example_1.py — Basic Case
$ Input: nums = [2, 2, 1], m = 4
Output: true
💡 Note: We can split [2,2,1] into [2,2] and [1]. Both parts are good: [2,2] has sum 4 ≥ m, and [1] has length 1. Then [2,2] can be split into [2] and [2], both with length 1.
example_2.py — Impossible Case
$ Input: nums = [2, 1, 2], m = 5
Output: false
💡 Note: No matter how we split [2,1,2], we cannot make both parts good. For example, splitting at position 1 gives [2] (good, length 1) and [1,2] (sum=3 < 5, length > 1, so not good).
example_3.py — Edge Case
$ Input: nums = [2, 3], m = 4
Output: true
💡 Note: Array has length 2, so it can always be split into individual elements regardless of their sum.

Constraints

  • 1 ≤ n ≤ 100
  • 1 ≤ nums[i] ≤ 100
  • 1 ≤ m ≤ 200
  • Key insight: Arrays of length ≤ 2 can always be split completely

Visualization

Tap to expand
Array Splitting Visualization: [2, 2, 1] with m=4221Split here: [2,2] sum=4≥m ✓ and [1] length=1 ✓[2,2] sum=4[1]Can split [2,2] → [2] + [2]Already length 1Result: TRUE - Complete splitting possible!
Understanding the Visualization
1
Check Base Cases
Length 1 arrays are done, length 2 can always split
2
Try Split Positions
For each position, check if both sides are 'good'
3
Recursive Splitting
If split is valid, recursively split both parts
4
Memoize Results
Store results to avoid recalculating same subarrays
Key Takeaway
🎯 Key Insight: Use dynamic programming with memoization to efficiently explore all splitting strategies. Arrays of length ≤ 2 are always splittable, making this a powerful base case for recursion.
Asked in
Google 45 Meta 38 Amazon 32 Microsoft 28
42.8K Views
Medium-High Frequency
~25 min Avg. Time
1.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen