FastPrepLongest Unique Substring Range
Problems/Longest Unique Substring Range

Longest Unique Substring Range

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to return the start and end indices of a longest substring with no repeats. It wants an O(n) sliding window and has a follow-up for large input. It does not give the index convention, a tie rule, the alphabet, or the input limits. Our version is about 94% the same as the reported question.

You are given a nonempty string text. Return [start, end], the zero-based inclusive indices of a longest contiguous substring whose characters are all distinct.

If several longest valid substrings exist, return the one with the smallest start index.

Process the string from left to right in O(text.length) time and use O(1) auxiliary space for the fixed printable-ASCII alphabet.

Follow-up

A sliding-window solution works. How should the approach change when the input is too large to keep in memory?

Function

longestUniqueSubstringRange(text: String) → int[]

Examples

Example 1

text = "abcabcbb"return = [0,2]

The maximum length is 3. The valid ranges [0,2], [1,3], [2,4], and [3,5] all have that length, so the earliest range is returned.

Example 2

text = "bbbbb"return = [0,0]

Every valid substring contains one b. The earliest one begins and ends at index 0.

Example 3

text = "pwwkew"return = [2,4]

Both wke at [2,4] and kew at [3,5] have maximum length 3. The earlier range is returned.

Example 4

text = "dvdf"return = [1,3]

After the second d, the window moves forward and the substring vdf becomes the unique maximum.

Constraints

  • 1 <= text.length <= 10^6.
  • text contains printable ASCII characters.
  • The returned range uses zero-based inclusive indices.
  • When several ranges have the same maximum length, return the earliest one.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Top K Best-Selling Products in the Last N DaysAmazon · ONSITE INTERVIEW
  • Longest Substring Without Repeating CharactersInfosys · ONSITE INTERVIEWInfosys interview questions
  • Longest Substring Without Repeating CharactersOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Longest Substring Without Repeating CharactersBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Longest Substring with At Most K Distinct CharactersGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Substring Without Repeating CharactersBank of America · ONSITE INTERVIEWBank of America interview questions
  • Sliding-Window Rate LimiterStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions

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
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] longestUniqueSubstringRange(String text) {
      // Write your code here.
    }
}
Checking account…