Skip to content

Practice Count Subarrays of Length Three With a Condition

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3392
LeetCode Problem

Count Subarrays of Length Three With a Condition

Problem Statement

Given an integer array nums, return the number of subarrays of length 3 such that the sum of the first and third numbers equals exactly half of the second number.

Source: Count Subarrays of Length Three With a Condition on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,1,4,1]
Output
1

# Example 2

Input
nums = [1,1,1]
Output
0

Constraints

3 <= nums.length <= 100
-100 <= nums[i] <= 100

Related LeetCode Problems

Practice more problems similar to Count Subarrays of Length Three With a Condition.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.