Maximize Beautiful Substrings
Updated
Problem statement
Given a string color, which contains lowercase letters (a-z) and dots (.) representing blank positions, you can replace each dot with any lowercase letter.
A beautiful substring is defined as a contiguous substring where all characters are the same. For example, "a", "bb", and "zzzz" are beautiful substrings, while "ab" and "aab" are not.
Your task is to:
- Replace each dot in the string with a lowercase letter;
- Maximize the total number of beautiful substrings in the final string.
Return the maximum possible number of beautiful substrings.
Function
maximizeBeautifulSubstrings(color: String) → intExamples
Example 1
color = ".a.bb."return = 13An optimal replacement would be: "aabbbb" The beautiful substrings include: "a", "a", "aa", "b", "b", "b", "bb", "bb", "bb", "bbb", "bbb", "bbb", "bbbb" In total: 13 beautiful substrings. Output: 13
More Fortinet interview questions
Similar questions at other companies
- Calculate Max SalaryAmazon · OA
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Most Relevant Text SpanHebbia · PHONE SCREEN
- Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
- Match a Pattern With ? and *Adobe · PHONE SCREENAdobe interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions