Dsa
Arrays
Medium
Consecutive Triplets
Given an array of integers, count the number of groups of three consecutive elements (i, i+1, i+2) such that the sum of these three elements is even. Return that count.
Input:
- The first line contains an integer n (1 <= n <= 1000), the number of elements in the array.
- The second line contains n space-separated integers, the elements of the array.
Output:
- Print a single integer: the number of triplet groups with an even sum.
Example:
Input:
6
1 2 3 4 5 6
Output:
2
Key concepts
arrayscounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now