Must be written in JavaScript. 7. [Problem Description] Amy was walking her path one day and warped to a world made of o

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Must be written in JavaScript. 7. [Problem Description] Amy was walking her path one day and warped to a world made of o

Post by answerhappygod »

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;
}
///
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply