Question: 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

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

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 #include 2 #include 3 4 using namespace std; 5 6 int solution(string s) { 7 cerr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!