FPEvalDataset/LeetCodeProblem
0302
1{2 "id": 2870,3 "name": "longest_alternating_subarray",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/longest-alternating-subarray/",6 "date": "2023-06-24 00:00:00",7 "task_description": "You are given a **0-indexed** integer array `nums`. A subarray `s` of length `m` is called **alternating** if: `m` is greater than `1`. `s1 = s0 + 1`. The **0-indexed** subarray `s` looks like `[s0, s1, s0, s1,...,s(m-1) % 2]`. In other words, `s1 - s0 = 1`, `s2 - s1 = -1`, `s3 - s2 = 1`, `s4 - s3 = -1`, and so on up to `s[m - 1] - s[m - 2] = (-1)m`. Return _the maximum length of all **alternating** subarrays present in _`nums` _or _`-1`_ if no such subarray exists__._ A subarray is a contiguous **non-empty** sequence of elements within an array. **Example 1:** **Input:** nums = [2,3,4,3,4] **Output:** 4 **Explanation:** The alternating subarrays are `[2, 3]`, `[3,4]`, `[3,4,3]`, and `[3,4,3,4]`. The longest of these is `[3,4,3,4]`, which is of length 4. **Example 2:** **Input:** nums = [4,5,6] **Output:** 2 **Explanation:** `[4,5]` and `[5,6]` are the only two alternating subarrays. They are both of length 2. **Constraints:** `2 <= nums.length <= 100` `1 <= nums[i] <= 104`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [2,3,4,3,4]",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "nums = [4,5,6]",17 "output": "2 "18 }19 ],20 "private_test_cases": [21 {22 "input": [23 54,24 16,25 32,26 95,27 67,28 55,29 86,30 56,31 31,32 70,33 16,34 68,35 90,36 20,37 43,38 33,39 67,40 50,41 75,42 12,43 55,44 63,45 26,46 45,47 31,48 55,49 17,50 20,51 83,52 34,53 63,54 51,55 82,56 103,57 88,58 88,59 8,60 66,61 76,62 85,63 93,64 24,65 4,66 70,67 5,68 40,69 46,70 99,71 88,72 88,73 8,74 40,75 58,76 22,77 39,78 37,79 39,80 92,81 29,82 26,83 44,84 90,85 38,86 15,87 48,88 77,89 76,90 10,91 96,92 7,93 26,94 7,95 95,96 9397 ],98 "output": -199 },100 {101 "input": [102 62,103 77,104 25,105 40,106 7,107 16,108 33,109 76,110 103,111 72,112 89,113 50,114 18,115 58,116 45,117 28,118 50,119 88,120 43,121 65,122 46,123 100,124 29,125 65,126 27,127 29,128 25,129 8,130 2,131 33,132 62,133 34,134 14,135 20,136 20,137 40,138 87,139 75,140 49,141 53,142 65,143 87,144 30,145 100,146 38,147 9,148 72,149 86,150 44,151 10,152 41,153 53,154 92,155 99,156 102,157 14,158 47,159 34160 ],161 "output": -1162 },163 {164 "input": [165 50,166 30,167 88,168 101,169 99,170 23,171 27,172 91,173 21174 ],175 "output": -1176 },177 {178 "input": [179 3,180 23,181 16,182 46183 ],184 "output": -1185 },186 {187 "input": [188 38,189 73,190 92,191 36,192 95,193 99,194 83,195 14,196 95,197 4,198 91,199 89,200 82,201 62,202 22,203 40,204 102,205 25,206 45,207 88,208 60,209 80,210 36,211 104,212 71,213 28,214 39,215 44,216 44,217 38,218 65,219 14,220 29,221 43,222 17,223 18,224 22,225 79,226 39,227 98,228 102,229 55,230 81,231 25,232 104,233 60,234 6235 ],236 "output": 2237 }238 ],239 "haskell_template": "alternatingSubarray :: [Int] -> Int\nalternatingSubarray nums ",240 "ocaml_template": "let alternatingSubarray (nums: int list) : int = ",241 "scala_template": "def alternatingSubarray(nums: List[Int]): Int = { \n \n}",242 "java_template": "class Solution {\n public int alternatingSubarray(int[] nums) {\n \n }\n}",243 "python_template": "class Solution(object):\n def alternatingSubarray(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n "244}