CoolFace
Datasetpublic

TheRealSamuel/LeetCodeProblem

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes564downloads
1{2    "id": 2466,3    "name": "maximum_segment_sum_after_removals",4    "difficulty": "Hard",5    "link": "https://leetcode.com/problems/maximum-segment-sum-after-removals/",6    "date": "1659744000000",7    "task_description": "You are given two **0-indexed** integer arrays `nums` and `removeQueries`, both of length `n`. For the `ith` query, the element in `nums` at the index `removeQueries[i]` is removed, splitting `nums` into different segments. A **segment** is a contiguous sequence of **positive** integers in `nums`. A **segment sum** is the sum of every element in a segment. Return_ an integer array _`answer`_, of length _`n`_, where _`answer[i]`_ is the **maximum** segment sum after applying the _`ith` _removal._ **Note:** The same index will **not** be removed more than once. **Example 1:** ``` **Input:** nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1] **Output:** [14,7,2,2,0] **Explanation:** Using 0 to indicate a removed element, the answer is as follows: Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1]. Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5]. Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2]. Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2]. Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments. Finally, we return [14,7,2,2,0]. ``` **Example 2:** ``` **Input:** nums = [3,2,11,1], removeQueries = [3,2,1,0] **Output:** [16,5,3,0] **Explanation:** Using 0 to indicate a removed element, the answer is as follows: Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11]. Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2]. Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3]. Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments. Finally, we return [16,5,3,0]. ``` **Constraints:** `n == nums.length == removeQueries.length` `1 <= n <= 105` `1 <= nums[i] <= 109` `0 <= removeQueries[i] < n` All the values of `removeQueries` are **unique**.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]",12            "output": "[14,7,2,2,0] "13        },14        {15            "label": "Example 2",16            "input": "nums = [3,2,11,1], removeQueries = [3,2,1,0]",17            "output": "[16,5,3,0] "18        }19    ],20    "private_test_cases": [],21    "haskell_template": "maximumSegmentSum :: [Int] -> [Int] -> [Int]\nmaximumSegmentSum nums removeQueries ",22    "ocaml_template": "let maximumSegmentSum (nums: int list) (removeQueries: int list) : int list =  ",23    "scala_template": "def maximumSegmentSum(nums: List[Int],removeQueries: List[Int]): List[Int] = { \n    \n}",24    "java_template": "public static List<Integer> maximumSegmentSum(List<Integer> nums, List<Integer> removeQueries) {\n\n}",25    "python_template": "class Solution(object):\n    def maximumSegmentSum(self, nums, removeQueries):\n        \"\"\"\n        :type nums: List[int]\n        :type removeQueries: List[int]\n        :rtype: List[int]\n        \"\"\"\n        "26}