TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2866,3 "name": "longest_even_odd_subarray_with_threshold",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/longest-even-odd-subarray-with-threshold/",6 "date": "2023-06-25 00:00:00",7 "task_description": "You are given a **0-indexed** integer array `nums` and an integer `threshold`. Find the length of the **longest subarray** of `nums` starting at index `l` and ending at index `r` `(0 <= l <= r < nums.length)` that satisfies the following conditions: `nums[l] % 2 == 0` For all indices `i` in the range `[l, r - 1]`, `nums[i] % 2 != nums[i + 1] % 2` For all indices `i` in the range `[l, r]`, `nums[i] <= threshold` Return _an integer denoting the length of the longest such subarray._ **Note:** A **subarray** is a contiguous non-empty sequence of elements within an array. **Example 1:** ``` **Input:** nums = [3,2,5,4], threshold = 5 **Output:** 3 **Explanation:** In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions. Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length. ``` **Example 2:** ``` **Input:** nums = [1,2], threshold = 2 **Output:** 1 **Explanation:** In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2]. It satisfies all the conditions and we can show that 1 is the maximum possible achievable length. ``` **Example 3:** ``` **Input:** nums = [2,3,4,5], threshold = 4 **Output:** 3 **Explanation:** In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4]. It satisfies all the conditions. Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length. ``` **Constraints:** `1 <= nums.length <= 100 ` `1 <= nums[i] <= 100 ` `1 <= threshold <= 100`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [3,2,5,4], threshold = 5",12 "output": "3 "13 },14 {15 "label": "Example 2",16 "input": "nums = [1,2], threshold = 2",17 "output": "1 "18 },19 {20 "label": "Example 3",21 "input": "nums = [2,3,4,5], threshold = 4",22 "output": "3 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 [29 53,30 12,31 16,32 68,33 39,34 99,35 81,36 24,37 65,38 67,39 59,40 84,41 17,42 39,43 42,44 1,45 87,46 59,47 34,48 4149 ],50 6051 ],52 "output": 253 },54 {55 "input": [56 [57 93,58 15,59 82,60 51,61 33,62 7,63 29,64 37,65 40,66 29,67 71,68 75,69 5,70 63,71 16,72 29,73 34,74 16,75 61,76 96,77 17,78 76,79 76,80 19,81 69,82 70,83 61,84 14,85 29,86 10,87 3788 ],89 1690 ],91 "output": 192 },93 {94 "input": [95 [96 5,97 89,98 86,99 41,100 61,101 81,102 6,103 24,104 48,105 36,106 58,107 2,108 76,109 25,110 18,111 51,112 75,113 1,114 51,115 7,116 43,117 9,118 30,119 30,120 41,121 41,122 11,123 79124 ],125 49126 ],127 "output": 2128 },129 {130 "input": [131 [132 76,133 86,134 22,135 69,136 47,137 36,138 46,139 12,140 56,141 6,142 77,143 30,144 77,145 36,146 65,147 10,148 32,149 48,150 62,151 75,152 58,153 65,154 39,155 3,156 9,157 21,158 24,159 68,160 93,161 6,162 34,163 80,164 84,165 5,166 4,167 70,168 5,169 46,170 30171 ],172 79173 ],174 "output": 7175 },176 {177 "input": [178 [179 7,180 49,181 35,182 59,183 41,184 43,185 27,186 60,187 13,188 47,189 39,190 16,191 56,192 74,193 76,194 87,195 17,196 61,197 30,198 9,199 99,200 99,201 42,202 25,203 18,204 95,205 56,206 86,207 41,208 87,209 53,210 87,211 32,212 25,213 87,214 62,215 58,216 60,217 71,218 74,219 16,220 67,221 76,222 85,223 78,224 23,225 10,226 4,227 96,228 96,229 57,230 46231 ],232 45233 ],234 "output": 3235 },236 {237 "input": [238 [239 50,240 2,241 70,242 95,243 9,244 66,245 2,246 82,247 95,248 84,249 33,250 65,251 44,252 66,253 83,254 17,255 1,256 29,257 92,258 8,259 96,260 100,261 6,262 74,263 96,264 71,265 78,266 73,267 53,268 9,269 45,270 79,271 90,272 57,273 72,274 49,275 87,276 79,277 80,278 67,279 50,280 68,281 89,282 15,283 89,284 39,285 45,286 51,287 52,288 59,289 21,290 12,291 87,292 74,293 52,294 30,295 47,296 23,297 23,298 56,299 62,300 13,301 16,302 51,303 96,304 64,305 18,306 12,307 71,308 22,309 39,310 95,311 48,312 4,313 39,314 42,315 78,316 59,317 11318 ],319 39320 ],321 "output": 2322 },323 {324 "input": [325 [326 99,327 70,328 43,329 46,330 94,331 9,332 54,333 6,334 6,335 71,336 16,337 38,338 38,339 77,340 57,341 96,342 23,343 71,344 62,345 12,346 72,347 32,348 67,349 64,350 69,351 19,352 40,353 58,354 52,355 72,356 53,357 3,358 38,359 68,360 46,361 17,362 20,363 13,364 96,365 75,366 17,367 31,368 14,369 31,370 87,371 2,372 51,373 1,374 42,375 11376 ],377 45378 ],379 "output": 2380 },381 {382 "input": [383 [384 68,385 67,386 25,387 41,388 20,389 45,390 71,391 46,392 84,393 36,394 50,395 98,396 4,397 59,398 55,399 32,400 80,401 33,402 37,403 4,404 71,405 26,406 77,407 26,408 100,409 52,410 41,411 47,412 46,413 39,414 43,415 93,416 15,417 18,418 58,419 38,420 6421 ],422 62423 ],424 "output": 2425 },426 {427 "input": [428 [429 33,430 2,431 53,432 21,433 56,434 19,435 58,436 56,437 72,438 63,439 92,440 40,441 96,442 10,443 44,444 49,445 73,446 51,447 59,448 15,449 27,450 95,451 98,452 82,453 10,454 8,455 33,456 32,457 79,458 25,459 41,460 66,461 68,462 82,463 61,464 76,465 57,466 48,467 81,468 7,469 20,470 25,471 72,472 79,473 7,474 51,475 68,476 28,477 80,478 61,479 5,480 53,481 29,482 31,483 30,484 94,485 9,486 47,487 40,488 88,489 19,490 33,491 56,492 98,493 58,494 46,495 6,496 93,497 69,498 55,499 7,500 85,501 75,502 14,503 45,504 79,505 27,506 76,507 31,508 81,509 98,510 89,511 3,512 20,513 48,514 65,515 67,516 43,517 20,518 71,519 55,520 21,521 80,522 32,523 5,524 82525 ],526 99527 ],528 "output": 6529 },530 {531 "input": [532 [533 24,534 75,535 21,536 32,537 53,538 32,539 30,540 65,541 67,542 72,543 10,544 91,545 62,546 99,547 51,548 33,549 13,550 66,551 80,552 49,553 79,554 80,555 45,556 97,557 4,558 51,559 92,560 76,561 67,562 71,563 99,564 81,565 12,566 83,567 28,568 19,569 60,570 44,571 55,572 84,573 85,574 31,575 37,576 12,577 61,578 42,579 26,580 21,581 9,582 56,583 19,584 46,585 32,586 3,587 51,588 22,589 44,590 37,591 39,592 3,593 12,594 68,595 71,596 73,597 81,598 50,599 97,600 90,601 4,602 59,603 72,604 33,605 26,606 17,607 12,608 94,609 15,610 70,611 11,612 90,613 42,614 27,615 12,616 37,617 45,618 63,619 6620 ],621 16622 ],623 "output": 1624 }625 ],626 "haskell_template": "longestAlternatingSubarray :: [Int] -> Int -> Int\nlongestAlternatingSubarray nums threshold ",627 "ocaml_template": "let longestAlternatingSubarray (nums: int list) (threshold: int) : int = ",628 "scala_template": "def longestAlternatingSubarray(nums: List[Int],threshold: Int): Int = { \n \n}",629 "java_template": "class Solution {\n public int longestAlternatingSubarray(int[] nums, int threshold) {\n \n }\n}",630 "python_template": "class Solution(object):\n def longestAlternatingSubarray(self, nums, threshold):\n \"\"\"\n :type nums: List[int]\n :type threshold: int\n :rtype: int\n \"\"\"\n "631}