CoolFace
Datasetpublic

TheRealSamuel/LeetCodeProblem

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes564downloads
1{2    "id": 3731,3    "name": "sum_of_variable_length_subarrays",4    "difficulty": "Easy",5    "link": "https://leetcode.com/problems/sum-of-variable-length-subarrays/",6    "date": "2025-01-12 00:00:00",7    "task_description": "You are given an integer array `nums` of size `n`. For **each** index `i` where `0 <= i < n`, define a subarray `nums[start ... i]` where `start = max(0, i - nums[i])`. Return the total sum of all elements from the subarray defined for each index in the array. **Example 1:** **Input:** nums = [2,3,1] **Output:** 11 **Explanation:** i Subarray Sum 0 `nums[0] = [2]` 2 1 `nums[0 ... 1] = [2, 3]` 5 2 `nums[1 ... 2] = [3, 1]` 4 **Total Sum** 11 The total sum is 11. Hence, 11 is the output. **Example 2:** **Input:** nums = [3,1,1,2] **Output:** 13 **Explanation:** i Subarray Sum 0 `nums[0] = [3]` 3 1 `nums[0 ... 1] = [3, 1]` 4 2 `nums[1 ... 2] = [1, 1]` 2 3 `nums[1 ... 3] = [1, 1, 2]` 4 **Total Sum** 13 The total sum is 13. Hence, 13 is the output. **Constraints:** `1 <= n == nums.length <= 100` `1 <= nums[i] <= 1000`",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "nums = [2,3,1]",12            "output": "11 "13        },14        {15            "label": "Example 2",16            "input": "nums = [3,1,1,2]",17            "output": "13 "18        }19    ],20    "private_test_cases": [21        {22            "input": [23                49,24                985,25                533,26                224,27                602,28                116,29                615,30                938,31                668,32                974,33                622,34                437,35                930,36                129,37                165,38                665,39                812,40                546,41                478,42                327,43                547,44                84,45                397,46                546,47                45,48                40,49                14,50                37,51                87,52                2,53                391,54                957,55                835,56                180,57                944,58                950,59                843,60                960,61                962,62                726,63                96,64                480,65                842,66                492,67                992,68                68769            ],70            "output": 51450171        },72        {73            "input": [74                582,75                41,76                803,77                568,78                745,79                96,80                718,81                367,82                192,83                344,84                927,85                340,86                297,87                315,88                481,89                8,90                969,91                320,92                283,93                565,94                607,95                703,96                734,97                31,98                728,99                735,100                34,101                897,102                171,103                344,104                570,105                513,106                731,107                570,108                736,109                754,110                919,111                866,112                380,113                641,114                147115            ],116            "output": 408941117        },118        {119            "input": [120                428,121                632,122                781,123                464,124                958,125                596,126                612,127                900,128                545,129                579,130                435,131                357,132                748,133                84,134                548,135                152,136                754,137                782,138                436,139                156,140                175,141                549,142                318,143                793,144                990,145                881,146                304,147                491,148                634,149                117,150                553,151                65,152                737,153                638,154                529,155                272,156                935,157                922158            ],159            "output": 411014160        },161        {162            "input": [163                640,164                345,165                535,166                711,167                195,168                114,169                123,170                973,171                274,172                356,173                846,174                230,175                90,176                592,177                486,178                809,179                786,180                684,181                908,182                576,183                424,184                541,185                699,186                327,187                940,188                654,189                438,190                91,191                831,192                531,193                423,194                535,195                79,196                72,197                450,198                192,199                802,200                587,201                704,202                75,203                972,204                607,205                85,206                280,207                792,208                21,209                839,210                846,211                263,212                925,213                438,214                531,215                508,216                676,217                151,218                805,219                475,220                164,221                973,222                667,223                564,224                915,225                781,226                859,227                567,228                230,229                300230            ],231            "output": 1137405232        },233        {234            "input": [235                858,236                782,237                632,238                395,239                53,240                800,241                808,242                422,243                867,244                470,245                71,246                832,247                475,248                380,249                419,250                156,251                867,252                614,253                778,254                930,255                537256            ],257            "output": 133223258        }259    ],260    "haskell_template": "subarraySum :: [Int] -> Int\nsubarraySum nums ",261    "ocaml_template": "let subarraySum (nums: int list) : int =  ",262    "scala_template": "def subarraySum(nums: List[Int]): Int = { \n    \n}",263    "java_template": "class Solution {\n    public int subarraySum(int[] nums) {\n        \n    }\n}",264    "python_template": "class Solution(object):\n    def subarraySum(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        "265}