Longest Even Odd Subarray With Threshold Problem
Longest Even Odd Subarray With Threshold Problem — ExecCode Easy DSA Practice
Solve the Longest Even Odd Subarray With Threshold problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed integer array nums and an integer threshold. Your task is to 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.
Examples
Input {"nums": [3, 2, 5, 4], "threshold": 5}; Output 3. Input {"nums": [1, 2], "threshold": 2}; Output 1
Constraints
1 <= nums.length <= 100 1 <= nums[i] <= 100 1 <= threshold <= 100
Practice Longest Even Odd Subarray With Threshold free on ExecCode. Browse DSA problems, topic map, and placement guides.