Laugh
InterviewTime limit1sMemory limit512 MB
Given a string, find the length of the longest substring made of alternating h and a characters.
- Level
Easy3 of 10
- Topics
- String, Implementation, Two pointers, Brute force
- Solved
- No attempts yet
Problem
Russian scientists are working on several promising topics. One of them is the quality of laugh. In this research they analyse human speech and extract the laugh from it.
The scientists already made software that converts speech to text. They consider a string of alternating letters “h” and “a” to be a laugh. For example, the strings “ahahaha”, “hah”, and “a” are laughs, but “abacaba” and “hh” are not.
You are given a string s containing the text. Find the length of the longest substring that is considered a laugh.