FastPrepMaximize Beautiful Substrings
Problems/Maximize Beautiful Substrings

Maximize Beautiful Substrings

Fortinet logoFortinet● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamples

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) → int

Examples

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 interview questions

  • Checksum AggregatorOA · Seen Jun 2025
  • K-Means ClusteringOA · Seen Jun 2025
  • Madam C.J. Walker's Business PlanOA · Seen Jun 2025
  • Signal PingsOA · Seen Jun 2025

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
All Fortinet interview questionsSee Fortinet hiring insights
Saved
class Solution {
    public int maximizeBeautifulSubstrings(String color) {
      // write your code here
    }

}
Checking account…