Maximum Substrings
Learn this problemProblem statement
The people in HackerLand, are getting ready for a parade. There should be no instance where a person is wearing a white-colored uniform. There is a given string color that contains lowercase English characters ('a' - 'z'). Some of the positions in the string are empty, meaning that the color of the uniform is white at that position and is denoted by the '.' character.
A beautiful string is defined as a string in which all characters are the same. For example "aaa", "zzzzz", "f" are beautiful while "aba", "aaad" are not beautiful. Replace each non-colored uniform with some lowercase English character such that the total number of substrings that are beautiful maximized.
Find the maximum total number of beautiful substrings after replacing every empty character.
Note: A substring of a string is a contiguous subsequence of that string.
Function
getMaxBeautifulSubstrings(color: String) → int
Complete the function getMaxBeautifulSubstrings in the editor.
getMaxBeautifulSubstrings has the following parameter(s):
string color: the color of each uniform
Returns
int: the maximum number of beautiful substrings possible
Examples
Example 1
color = ".a.bb."return = 13Example 2
color = "p.r."return = 7Constraints
1 ≤ |color| ≤ 5000More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026