Problem · String
Maximize Beautiful Substrings
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:
Return the maximum possible number of beautiful substrings.
Examples
01 · Example 1
color = ".a.bb." return = 13
An 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 problems
public int maximizeBeautifulSubstrings(String color) {
// write your code here
}
color".a.bb."
expected13
sign in to submit