Question bank › Two Pointers
Dsa Two Pointers Easy

Balanced Pair Count

You are given an array of integers, and your task is to count the number of pairs (i, j) such that i < j and the sum of the elements at these indices is even. A sum is even if both elements are even or both are odd. Write a function that reads the input data and prints the count of such pairs. Input Format: - The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of elements in the array. - The second line contains n space-separated integers a_i (1 ≤ a_i ≤ 10^9) — the elements of the array. Output Format: - Print the total count of valid pairs. Example: Input: 5 1 2 3 4 5 Output: 6

Key concepts

two_pointersarraycounting

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.