Problem: Count Subarrays of Length Three With a Condition
med
30 min
Try to solve the Count Subarrays of Length Three With a Condition problem.
Statement
Given an integer array nums, return the number of contiguous subarrays of length 3 such that the sum of the first and third elements is equal to half of the middle element.
Constraints:
3≤nums.length≤100
−100≤nums[i]≤100
Examples
Fetching Slides...
Understand the problem
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Count Subarrays of Length Three With a Condition
1.
For the input \([2,8,2,0,0,0]\\), how many contiguous subarrays of length (3) satisfy that the sum of the first and third elements equals half of the middle element?
A.
(1)
B.
(3)
C.
(2)
D.
(0)
1 / 3
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence
1
2
3
4
5
Try it yourself
Implement your solution in the following coding playground.
Problem: Count Subarrays of Length Three With a Condition
med
30 min
Try to solve the Count Subarrays of Length Three With a Condition problem.
Statement
Given an integer array nums, return the number of contiguous subarrays of length 3 such that the sum of the first and third elements is equal to half of the middle element.
Constraints:
3≤nums.length≤100
−100≤nums[i]≤100
Examples
Fetching Slides...
Understand the problem
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Count Subarrays of Length Three With a Condition
1.
For the input \([2,8,2,0,0,0]\\), how many contiguous subarrays of length (3) satisfy that the sum of the first and third elements equals half of the middle element?
A.
(1)
B.
(3)
C.
(2)
D.
(0)
1 / 3
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence
1
2
3
4
5
Try it yourself
Implement your solution in the following coding playground.