Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
number-of-ways-to-split-array.json31 linesDownload Raw Back to root
1{2  "id": 2358,3  "name": "number-of-ways-to-split-array",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/number-of-ways-to-split-array/",6  "date": "2022-04-30",7  "task_description": "You are given a **0-indexed** integer array `nums` of length `n`. `nums` contains a **valid split** at index `i` if the following are true: The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last `n - i - 1` elements. There is **at least one** element to the right of `i`. That is, `0 <= i < n - 1`. Return _the number of **valid splits** in_ `nums`. **Example 1:** ``` **Input:** nums = [10,4,-8,7] **Output:** 2 **Explanation:** There are three ways of splitting nums into two non-empty parts: - Split nums at index 0. Then, the first part is [10], and its sum is 10. The second part is [4,-8,7], and its sum is 3. Since 10 >= 3, i = 0 is a valid split. - Split nums at index 1. Then, the first part is [10,4], and its sum is 14. The second part is [-8,7], and its sum is -1. Since 14 >= -1, i = 1 is a valid split. - Split nums at index 2. Then, the first part is [10,4,-8], and its sum is 6. The second part is [7], and its sum is 7. Since 6 < 7, i = 2 is not a valid split. Thus, the number of valid splits in nums is 2. ``` **Example 2:** ``` **Input:** nums = [2,3,1,0] **Output:** 2 **Explanation:** There are two valid splits in nums: - Split nums at index 1. Then, the first part is [2,3], and its sum is 5. The second part is [1,0], and its sum is 1. Since 5 >= 1, i = 1 is a valid split. - Split nums at index 2. Then, the first part is [2,3,1], and its sum is 6. The second part is [0], and its sum is 0. Since 6 >= 0, i = 2 is a valid split. ``` **Constraints:** `2 <= nums.length <= 105` `-105 <= nums[i] <= 105`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [10,4,-8,7]",12      "output": "2 "13    },14    {15      "label": "Example 2",16      "input": "nums = [2,3,1,0]",17      "output": "2 "18    }19  ],20  "constraints": [21    "The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.",22    "There is at least one element to the right of i. That is, 0 <= i < n - 1.",23    "2 <= nums.length <= 105",24    "-105 <= nums[i] <= 105"25  ],26  "python_template": "class Solution(object):\n    def waysToSplitArray(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        ",27  "java_template": "class Solution {\n    public int waysToSplitArray(int[] nums) {\n        \n    }\n}",28  "metadata": {29    "func_name": "waysToSplitArray"30  }31}