FastPrepLongest Duplicate Substring
Problems/Longest Duplicate Substring

Longest Duplicate Substring

Google logoGoogle● HardINTERNNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was a PhD intern interview. The report points directly to a well-known problem. That problem accepts any longest duplicate, so we add a lexicographic tie-breaker to make the answer always the same. Our version is about 97% the same as the reported question.

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

Examples

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.
  • s contains 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

Interview reports that mention this question

  • Google Intern Coding and OOP: 19 Experiences (Part 5 of 8)
  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String longestDuplicateSubstring(String s) {
        // Write your code here.
    }
}
Checking account…