PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Google

Find longest duplicated substring

Last updated: May 4, 2026

Quick Overview

This question evaluates proficiency in string algorithms, pattern matching, and algorithmic complexity analysis, focusing on designing efficient data structures and algorithms for finding repeated substrings.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Find longest duplicated substring

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a string `s` consisting of lowercase English letters. A **substring** of `s` is any contiguous sequence of characters, i.e., `s[i..j)` for `0 ≤ i < j ≤ len(s)`. Design an algorithm to find **any one** of the longest substrings that appears **at least twice** in `s`. The two occurrences may overlap. If no substring appears at least twice, return the empty string. ### Requirements - Input: a string `s` of length `n` (e.g., `1 ≤ n ≤ 2 × 10^5`). - Output: a string representing one of the longest duplicated substrings. - Aim for an algorithm substantially better than the naive `O(n^2)` substring comparison approach. ### Examples - `s = "banana"` - Possible duplicated substrings: "a", "an", "ana" - Longest length is 3 ("ana"), so acceptable outputs include `"ana"`. - `s = "abcd"` - No duplicated substring, so output should be `""` (empty string). Describe your algorithm, its time and space complexity, and how it scales for large `n`.

Quick Answer: This question evaluates proficiency in string algorithms, pattern matching, and algorithmic complexity analysis, focusing on designing efficient data structures and algorithms for finding repeated substrings.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Dec 8, 2025, 7:29 PM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given a string s consisting of lowercase English letters.

A substring of s is any contiguous sequence of characters, i.e., s[i..j) for 0 ≤ i < j ≤ len(s).

Design an algorithm to find any one of the longest substrings that appears at least twice in s. The two occurrences may overlap. If no substring appears at least twice, return the empty string.

Requirements

  • Input: a string s of length n (e.g., 1 ≤ n ≤ 2 × 10^5 ).
  • Output: a string representing one of the longest duplicated substrings.
  • Aim for an algorithm substantially better than the naive O(n^2) substring comparison approach.

Examples

  • s = "banana"
    • Possible duplicated substrings: "a", "an", "ana"
    • Longest length is 3 ("ana"), so acceptable outputs include "ana" .
  • s = "abcd"
    • No duplicated substring, so output should be "" (empty string).

Describe your algorithm, its time and space complexity, and how it scales for large n.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.