fun longestAlternatingSubarray(nums: IntArray, threshold: Int): Int {
var i = 0
val n = nums.size
var ans = 0
while (i < n) {
if (nums[i] % 2 != 0 || nums[i] > threshold) {
i++
continue
}
val start = i
i++
while (i < n && nums[i] <= threshold && nums[i - 1] % 2 != nums[i] % 2) {
i++
}
val end = i
ans = maxOf(ans, end - start)
}
return ans
}