Question bank › Strings
Dsa Strings Medium

Longest Alternating Character Substring

Given a string `s`, write a program to find the length of the longest substring where no two adjacent characters are the same. Return this length. ### Input Format: - A single line containing the string `s` (1 <= |s| <= 1000). ### Output Format: - A single integer representing the length of the longest alternating character substring. ### Example: Input: abacabadabac Output: 5 Explanation: The longest alternating substring is 'abaca', which has length 5.

Key concepts

stringssubstringsalternating

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