Dsa
Two Pointers
Easy
Character Pair Counter
You are given an array of characters. Count how many pairs of characters there are in a given array, considering pairs are identical characters that appear in consecutive indices. Write a program to determine the total number of such pairs.
Input:
- A single line containing space-separated characters (1 ≤ |arr| ≤ 100000).
Output:
- An integer representing the total number of pairs of identical characters.
Example:
Input:
a b a a b b
Output:
3
Key concepts
two_pointersarrayscount
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