Number of Great Partitions

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 10^9 + 7.

Two partitions are considered distinct if some element nums[i] is in different groups in the two partitions.

Example 1
Inputnums = [1,2,3,4], k = 4
Output6
The great partitions are ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]), and ([4], [1,2,3]).
Example 2
Inputnums = [3,3,3], k = 4
Output0
There are no great partitions for this array.

Constraints

  • 1 <= nums.length, k <= 1000
  • 1 <= nums[i] <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate