Dsa
Hashing
Easy
Count Character Pairs
Given a string, count all unique pairs of characters that appear together as a substring in the string. Each pair should be reported in lexicographical order of the characters.
Input format:
- The first line contains the string s (1 <= |s| <= 1000).
Output format:
- Print each unique pair of characters followed by their count. The output should be sorted by the pairs.
Example:
Input:
aabc
Output:
aa 1
aa 1
ab 1
ac 1
Key concepts
hashingstringscounting
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