Must be written in JavaScript. 7. [Problem Description] Amy was walking her path one day and warped to a world made of o
Posted: Thu Jul 14, 2022 2:17 pm
Must be written in JavaScript.
7.
[Problem Description]
Amy was walking her path one day and warped to a worldmade of only a and b.
She has to solve a string algorithm, and she is given amission to return to her original world, and she has to solveit.
The string algorithm wants to find the longest substringthat can be made by changing n strings of a and b to a and b toa.
Longest substring is 'aaaaaa' and 'bbbb' when there is astring such as 'aaaaabbbb', and 'aaaaa' and 'bbbb' are the possiblecandidates for the longest substring, and 'aaaaa' is the longeststring with the same characters. Therefore, the longest substringof 'aaaaabbbb' is 'aaaaa'.
Also, in the case of 'abbbaababa', there are fourpossible candidate strings: 'bbb', 'aa', 'a', and 'b'. where thelongest substring, which is the longest string of the samecharacters, is 'bbb'.
In this case, return the length of the longest substringamong the strings that can be made by changing a to b and b to afor n strings.
For example, given the string 'abab' and there is asituation where n=2, we can change 2 a to b, or 2 b to a to changeto 'aaaa' or (bbbb' string, the longest part The length of thestring is 4, so just return 4.
[Restrictions]
- n is 1 or more and 100,000 or less, and the length of thestring is 0 or more and n or less.
[Input format]
- You are given the number of mutable strings n and the stringab.
[Output Format]
- Print the length of the longest substring of the given stringk.
///
function solution(n, ab) {
var answer = 0;
return answer;
}
///
7.
[Problem Description]
Amy was walking her path one day and warped to a worldmade of only a and b.
She has to solve a string algorithm, and she is given amission to return to her original world, and she has to solveit.
The string algorithm wants to find the longest substringthat can be made by changing n strings of a and b to a and b toa.
Longest substring is 'aaaaaa' and 'bbbb' when there is astring such as 'aaaaabbbb', and 'aaaaa' and 'bbbb' are the possiblecandidates for the longest substring, and 'aaaaa' is the longeststring with the same characters. Therefore, the longest substringof 'aaaaabbbb' is 'aaaaa'.
Also, in the case of 'abbbaababa', there are fourpossible candidate strings: 'bbb', 'aa', 'a', and 'b'. where thelongest substring, which is the longest string of the samecharacters, is 'bbb'.
In this case, return the length of the longest substringamong the strings that can be made by changing a to b and b to afor n strings.
For example, given the string 'abab' and there is asituation where n=2, we can change 2 a to b, or 2 b to a to changeto 'aaaa' or (bbbb' string, the longest part The length of thestring is 4, so just return 4.
[Restrictions]
- n is 1 or more and 100,000 or less, and the length of thestring is 0 or more and n or less.
[Input format]
- You are given the number of mutable strings n and the stringab.
[Output Format]
- Print the length of the longest substring of the given stringk.
///
function solution(n, ab) {
var answer = 0;
return answer;
}
///