FPEvalRepoPublic/LeetCodeMetaData
0399
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",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 "test_case": [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 "constraints": [26 "nums[l] % 2 == 0",27 "For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2",28 "For all indices i in the range [l, r], nums[i] <= threshold",29 "1 <= nums.length <= 100",30 "1 <= nums[i] <= 100",31 "1 <= threshold <= 100"32 ],33 "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 ",34 "java_template": "class Solution {\n public int longestAlternatingSubarray(int[] nums, int threshold) {\n \n }\n}",35 "metadata": {36 "func_name": "longestAlternatingSubarray"37 }38}