From e005e72b441ae5d8f214adaace18a2312f8be2cf Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Sat, 26 Apr 2025 01:27:38 -0600 Subject: 2444. count subarrays with fixed bounds --- count_subarr_fixed_bound.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'count_subarr_fixed_bound.py') diff --git a/count_subarr_fixed_bound.py b/count_subarr_fixed_bound.py index 44fd99c..7409f42 100644 --- a/count_subarr_fixed_bound.py +++ b/count_subarr_fixed_bound.py @@ -17,15 +17,15 @@ class Solution(object): :type maxK: int :rtype: int """ - ans, last_min, last_max, bad = 0, -1, -1, -1 + ans, prev_min, prev_max, bad = 0, -1, -1, -1 for i, a in enumerate(nums): if not minK <= a <= maxK: bad = i if a == minK: - last_min = i + prev_min = i if a == maxK: - last_max = i - ans += max(0, min(last_min, last_max) - bad) + prev_max = i + ans += max(0, min(prev_min, prev_max) - bad) return ans -- cgit v1.2.3