3685. Count Subarrays of Length Three With a Condition
My accepted Python solution to LeetCode problem 3685, Count Subarrays of Length Three With a Condition, running in 8ms.
- Difficulty: Easy
- Python
- Runtime 8ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 8ms, memory 17.2MB, accepted 2026-01-01.
class Solution:
def countSubarrays(self, nums: List[int]) -> int:
count = 0
for i in range(len(nums) - 2):
first, second, third = nums[i], nums[i+1], nums[i+2]
if (first + third) * 2 == second:
count += 1
return count