3392. Count Subarrays of Length Three With a Condition

UMPIRE - [U]nderstand the problem, ask questions and come up with corner test cases. - [M]atch the leetcode pattern - [P]lan to using pattern template and data structures - [I]mplement the code - [R]eview by running the example and corner test cases - [E]valuate time and space complexity Understand Return number of length 3 sub arrays whose nums[1]/2 == nums[0] + nums[2] Brute force We can generate all sub arrays of length 3 O(n^2)....

April 26, 2025 · 1 min · 143 words · Me

2444. Count Subarrays With Fixed Bounds

UMPIRE - [U]nderstand the problem, ask questions and come up with corner test cases. - [M]atch the leetcode pattern - [P]lan to using pattern template and data structures - [I]mplement the code - [R]eview by running the example and corner test cases - [E]valuate time and space complexity Understand Need to count subarrays where min = minK and max = maxK Brute force Generate all sub arrays, track min and max Time complexity O(n^2) fails for constraint n = 10^5 Match Sliding window?...

April 25, 2025 · 2 min · 366 words · Me

2845. Count of Interesting Subarrays

UMPIRE - [U]nderstand the problem, ask questions and come up with corner test cases. - [M]atch the leetcode pattern - [P]lan to using pattern template and data structures - [I]mplement the code - [R]eview by running the example and corner test cases - [E]valuate time and space complexity Understand Need to count subarrays where cnt is number of element such that nums[i] % modulo == k and cnt % modulo == k Brute force Generate all sub arrays, calculate cnt and verify cnt % modulo == k....

April 24, 2025 · 3 min · 427 words · Me

2799. Count Complete Subarrays in an Array

UMPIRE - [U]nderstand the problem, ask questions and come up with corner test cases. - [M]atch the leetcode pattern - [P]lan to using pattern template and data structures - [I]mplement the code - [R]eview by running the example and corner test cases - [E]valuate time and space complexity Understand Need to count the sub arrays the have same number of distinct elements as the array For [1,3,1,2,2] Subarrays starting with index 0 and 3 distinct elements [1, 3, 1, 2] ad [1, 3, 1, 2, 2] Subarrays starting with index 1 and 3 distinct elements [3, 1, 2] ad [3, 1, 2, 2] Total 4 Brute force Generate all sub arrays and also maintain distinct count Time complexity O(n^2) it passes for given constraints def countCompleteSubarrays(self, nums: List[int]) -> int: arr_distinct = len(set(nums)) res = 0 for i in range(len(nums)): sub = set() for j in range(i, len(nums)): sub....

April 23, 2025 · 2 min · 286 words · Me