Find the Shortest Repeating Unit of a Telemetry Signature String

Last updated: November 29, 2026

Quick Overview

Given a string, return the shortest substring p such that the string is p repeated a whole number of times (for example "abc" for "abcabcabc"), or the string itself if no shorter unit exists, in linear time.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a string, return the shortest substring p such that the string is p repeated a whole number of times (for example "abc" for "abcabcabc"), or the string itself if no shorter unit exists, in linear time.

Monitoring systems at Google look for periodic patterns, such as a heartbeat signature repeating in a device telemetry stream. This screen question starts with the obvious divisor check and pushes toward a linear-time KMP prefix-function solution and a proof of why it works.

What the Interviewer Expects
  • Gives the divisor-checking brute force and its cost
  • Uses the KMP prefix function (longest proper border)
  • Derives the period as n minus the longest border
  • Checks divisibility to decide whether the period tiles the string
  • Mentions the doubled-string trick as an alternative
Key Topics to Cover
KMP Prefix Function
String Periodicity
Borders
Linear Time
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the number of repetitions as well, and handle a stream where characters keep arriving.
  • Find the smallest period that tiles the string except for a partial last copy.
  • Explain why (s + s).find(s, 1) also finds the period.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: a string s (possibly empty). Output: the shortest p with s == p * k for some k >= 1.
  • If no shorter unit tiles the string, return s.
  • Target linear time; strings can be millions o...
High-Level Design

A brute force tries each divisor d of n and checks s == s[:d] * (n // d), which is O(n * number of divisors). The linear approach uses the KMP prefix function: fail[i] is the length of the lon...


Submit Your Answer
Markdown supported