Check if it is Possible to Split Array

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.

Example 1
Inputnums = [2,2,1], m = 4
Outputtrue
Split [2, 2, 1] into [2, 2] and [1], then split [2, 2] into [2] and [2], with every resulting array good.
Example 2
Inputnums = [2,1,3], m = 5
Outputfalse
Both possible first splits leave a length-two subarray whose sum is less than m, so no valid split sequence exists.

Constraints

  • 1 <= n == nums.length <= 100
  • 1 <= nums[i] <= 100
  • 1 <= m <= 200

Asked at 1 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