LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 8ms, memory 17.2MB, accepted 2026-01-01.

python
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

Source