Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A coding problem, use C++ with starter coding, thanks You are given a string S consisting of N lowercase letters of the English alphabet. Find
A coding problem, use C++ with starter coding, thanks
You are given a string S consisting of N lowercase letters of the English alphabet. Find the length of the longest substring of Sin which the number of occurrences of each letter is equal. For example, given S = 'ababbcbc", substrings in which every letter occurs the same number of times are: "a", "b", "c", "ab", "ba", "bb", "bo", "cb", "abab" and "bcbc". The longest among them are "abab" and "bcbc" and their length equals 4. Write a function: int solution(string &S); that, given the string S of length N, returns the length of the longest substring in which the number of occurrences of each letter is equal. Examples: 1. Given S = "ababbcbc", the function should return 4, as explained above. 2. Given S = "aabcde", the function should return 5. The longest substring is "abcde", in which all letters occur once. 3. Given S = "aaaa", the function should return 4. that, given the string S of length N, returns the length of the longest substring in which the number of occurrences of each letter is equal. Examples: 1. Given S = "ababbcbc", the function should return 4, as explained above. 2. Given S = "aabcde", the function should return 5. The longest substring is "abcde", in which all letters occur once. 3. Given S = "aaaa", the function should return 4. The longest substring is 'aaaa', in which all letters occur four times. 4. Given S = "daababbd", the function should return 6. The longest substring is 'aababb", in which all letters occur three times. Assume that: N is an integer within the range [1..80); string S consists only of lowercase letters (a-z). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment. C++ Keyboard navigation: Use Tab to advance the cursor. To exit the editor, press the ctrl and [ keys 1 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started