Number of Great Partitions - Problem
You are given an array nums consisting of positive integers and an integer k.
Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of elements of each group is greater than or equal to k.
Return the number of distinct great partitions. Since the answer may be too large, return it modulo 109 + 7.
Two partitions are considered distinct if some element nums[i] is in different groups in the two partitions.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,1], k = 2
›
Output:
1
💡 Note:
Only one great partition: Group A = {1,1} with sum 2, Group B = {2} with sum 2. Both sums ≥ k=2.
Example 2 — Multiple Partitions
$
Input:
nums = [3,3,3], k = 4
›
Output:
0
💡 Note:
No great partitions possible. To have both groups with sum ≥ 4, we would need total sum ≥ 8, but with [3,3,3] the maximum one group can have is 6 (two elements) while the other gets 3, which is < 4.
Example 3 — Impossible Case
$
Input:
nums = [1,1,1,1], k = 5
›
Output:
0
💡 Note:
Total sum is 4, but we need both groups to have sum ≥ 5. Impossible since 4 < 2×5.
Constraints
- 1 ≤ nums.length ≤ 1000
- 1 ≤ nums[i] ≤ 100
- 1 ≤ k ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code