Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
check-if-it-is-possible-to-split-array.json45 linesDownload Raw Back to root
1{2  "id": 2916,3  "name": "check-if-it-is-possible-to-split-array",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/check-if-it-is-possible-to-split-array/",6  "date": "2023-07-30",7  "task_description": "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:** **Input:** nums = [2, 2, 1], m = 4 **Output:** true **Explanation:** Split `[2, 2, 1]` to `[2, 2]` and `[1]`. The array `[1]` has a length of one, and the array `[2, 2]` has the sum of its elements equal to `4 >= m`, so both are good arrays. Split `[2, 2]` to `[2]` and `[2]`. both arrays have the length of one, so both are good arrays. **Example 2:** **Input:** nums = [2, 1, 3], m = 5 **Output:** false **Explanation:** The first move has to be either of the following: Split `[2, 1, 3]` to `[2, 1]` and `[3]`. The array `[2, 1]` has neither length of one nor sum of elements greater than or equal to `m`. Split `[2, 1, 3]` to `[2]` and `[1, 3]`. The array `[1, 3]` has neither length of one nor sum of elements greater than or equal to `m`. So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split `nums` into `n` arrays of size 1. **Example 3:** **Input:** nums = [2, 3, 3, 2, 3], m = 6 **Output:** true **Explanation:** Split `[2, 3, 3, 2, 3]` to `[2]` and `[3, 3, 2, 3]`. Split `[3, 3, 2, 3]` to `[3, 3, 2]` and `[3]`. Split `[3, 3, 2]` to `[3, 3]` and `[2]`. Split `[3, 3]` to `[3]` and `[3]`. **Constraints:** `1 <= n == nums.length <= 100` `1 <= nums[i] <= 100` `1 <= m <= 200`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [2, 2, 1], m = 4",12      "output": "true "13    },14    {15      "label": "Example 2",16      "input": "nums = [2, 1, 3], m = 5",17      "output": "false "18    },19    {20      "label": "Example 3",21      "input": "nums = [2, 3, 3, 2, 3], m = 6",22      "output": "true "23    }24  ],25  "constraints": [26    "The length of the array is one, or",27    "The sum of the elements of the array is greater than or equal to m.",28    "Split [2, 2, 1] to [2, 2] and [1]. The array [1] has a length of one, and the array [2, 2] has the sum of its elements equal to 4 >= m, so both are good arrays.",29    "Split [2, 2] to [2] and [2]. both arrays have the length of one, so both are good arrays.",30    "Split [2, 1, 3] to [2, 1] and [3]. The array [2, 1] has neither length of one nor sum of elements greater than or equal to m.",31    "Split [2, 1, 3] to [2] and [1, 3]. The array [1, 3] has neither length of one nor sum of elements greater than or equal to m.",32    "Split [2, 3, 3, 2, 3] to [2] and [3, 3, 2, 3].",33    "Split [3, 3, 2, 3] to [3, 3, 2] and [3].",34    "Split [3, 3, 2] to [3, 3] and [2].",35    "Split [3, 3] to [3] and [3].",36    "1 <= n == nums.length <= 100",37    "1 <= nums[i] <= 100",38    "1 <= m <= 200"39  ],40  "python_template": "class Solution(object):\n    def canSplitArray(self, nums, m):\n        \"\"\"\n        :type nums: List[int]\n        :type m: int\n        :rtype: bool\n        \"\"\"\n        ",41  "java_template": "class Solution {\n    public boolean canSplitArray(List<Integer> nums, int m) {\n        \n    }\n}",42  "metadata": {43    "func_name": "canSplitArray"44  }45}