Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help this simple Java problem , use starter coding (below). Thanks You are given a string S consisting of N lowercase letters of the

Please help this simple Java problem, use starter coding (below). Thanks

image text in transcribed

image text in transcribed

image text in transcribed

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. Java eyboard navigation: Use Tab to advance the cursor. To exit the editor, press the ctrl and [ keys. class Solution { public static int solution(String S) { System.err.println("Tip: Use System.err.println() to write debug messages on the output tab."); return; } 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions