Maximize Repeated Substring Length
Learn this problemProblem statement
You are given a string S, consisting of lowercase Latin letters and/or question marks (?), your goal is to replace each question mark with any lowercase Latin letter (from 'a' to 'z') in such a way that the length of the longest repeated substring is maximized.
- A repeated substring is a segment/substring of even length within the string where the first half is identical to the second half.
- A substring is any contiguous portion of the string.
Objective: Replace each question mark in the string S with lowercase Latin letters to create the longest possible repeated substring.
Input Format
The only line of input contains a string S, consisting only of lowercase Latin letters and/or question marks.
Output Format
Print a single integer, the maximum length of the longest repeated substring as you replace each question mark in the string with some lowercase Latin letter.
Function
maximizeRepeatedSubstringLength(s: String) → intExamples
Example 1
s = "a??a"return = 4More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026