Longest Duplicate Substring
Updated
Problem statement
You are given a lowercase string s. A duplicate substring is a non-empty contiguous substring that occurs at least twice in s. The occurrences may overlap.
Return a duplicate substring of maximum length. If several different substrings have maximum length, return the lexicographically smallest one. Return an empty string if no duplicate substring exists.
Function
longestDuplicateSubstring(s: String) → StringExamples
Example 1
s = "banana"return = "ana"ana occurs twice and no longer substring occurs at least twice.
Example 2
s = "abcd"return = ""No non-empty substring appears twice.
Example 3
s = "aaaaa"return = "aaaa"The two overlapping occurrences start at indices 0 and 1.
Constraints
2 <= s.length <= 30000.scontains only lowercase English letters.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Time Based Key-Value StoreZillow · PHONE SCREENZillow interview questions
- Split Tender Part 4 - RefundsStripe · OA · PHONE SCREENStripe interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Window SubstringLyft · PHONE SCREENLyft interview questions
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Versioned Social NetworkOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Count Distinct Rooted-Tree GraftsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Minimum Window SubstringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN