FastPrepMaximize Repeated Substring Length
Problems/Maximize Repeated Substring Length

Maximize Repeated Substring Length

Amazon logoAmazon● HardOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a string s made of lowercase English letters and question marks (?). Replace every question mark with any lowercase letter you like.

A repeat is a substring (a block of characters next to each other) of even length whose first half is exactly the same as its second half. For example, abab and zz are repeats, but abba is not.

Choose the replacements so that the longest repeat in the final string is as long as possible, and return that length. If no repeat can be made, return 0.

Function

maximizeRepeatedSubstringLength(s: String) → int

Examples

Example 1

s = "a??a"return = 4

Replace both question marks with a to get aaaa. Its first half aa equals its second half aa, so the whole string is a repeat of length 4, the longest possible.

Constraints

  • 1 ≤ s.length ≤ 2000
  • s contains only lowercase English letters and ?.

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
  • Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
  • Distinct MovesMeesho · OA
  • Compressed Representation SizeMicrosoft · OAMicrosoft interview questions
  • Find Minimum OperationsIBM · OAIBM interview questions
  • String Challenge (Generic)TikTok · OATikTok interview questions
  • Maximize the Lottery IDCitadel · OACitadel interview questions
  • Sum of All ValuesFlexport · OAFlexport interview questions
  • Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int maximizeRepeatedSubstringLength(String s) {
      // write your code here
    }

}
Checking account…