Question: An array of N words is given. Each word consists of small letters ( ' a ' ' z ' ) . Our goal is
An array of N words is given. Each word consists of small letters az Our goal is to concatenate the words in such a way as to obtain a single word with the longest possible substring composed of one particular letter. Find the length of such a substring.
Write a function:
class Solution public int solutionString words;
that, given an array words containing N strings, returns the length of the longest substring of a word created as described above.
Examples:
Given N and wordsaabb "aaaa", "bbab" your function should return One of the best concatenations is words words words "aaaaaabbbbab". The longest substring is composed of letter a and its length is
Given N and wordsxxbxxxbxx your function should return One of the best concatenations is words words wordsxxbxxxxbx The longest substring is composed of letter x and its length is
Given N and wordsddbbccdd your function should return One of the best concatenations is words words words wordsddddbbcc The longest substring is composed of letter d and its length is
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
all the words are nonempty and consist only of lowercase letters az;
S denotes the sum of the lengths of words; S is an integer within the range
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
