← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Google SWE interview with a string indexing problem that sounds deceptively simple until you start thinking about the multi-digit case.

Questions Asked (1)

Q1

You're given a string of pi's digits. Using 1-based indexing, find all indices i where the substring of pi starting at position i (with length equal to the number of digits in i) matches i itself. Return the full list of such indices.

Algorithms & Data Structures
Author's notes

The single-digit case is fine, you just check pi[i] == i and move on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient algorithm that iterates through possible starting indices, computes the length of the index, and checks if the substring matches the index as a string. Discuss time and space complexity, and consider optimizations like early termination or precomputation if needed.

Pro tip: Demonstrate awareness of edge cases such as indices near the end of the string where the substring might be shorter than the index length, and mention that the solution should handle large inputs efficiently by avoiding unnecessary substring creations.

1. Understand the problem

Restate the problem in your own words and confirm details like 1-based indexing, the definition of 'length equal to the number of digits in i', and that the substring must exactly match the decimal representation of i.

2. Identify constraints and edge cases

Consider the length of pi's digits (could be large), indices near the end where the substring might be out of bounds, and indices with varying digit lengths (e.g., 1-digit, 2-digit, etc.).

3. Design an algorithm

Iterate over possible starting indices i from 1 to n, compute the number of digits d of i, check if i+d-1 <= n, and compare the substring of length d starting at i-1 (0-based) with the string representation of i. Collect matches.

4. Analyze complexity and optimize

Discuss time complexity O(n * d) where d is the average number of digits, and space complexity O(1) excluding output. Mention potential optimizations like avoiding substring creation by comparing characters directly.

5. Test with examples

Walk through a small example (e.g., pi digits '31415926') to verify the algorithm, and test edge cases like no matches or matches at the very end.

Key Points to Mention

  • 1-based indexing vs 0-based indexing in code
  • Handling indices with different digit lengths (e.g., 1-digit, 2-digit, 3-digit)
  • Boundary condition: ensuring the substring does not exceed the string length
  • Efficient string comparison without creating unnecessary substrings
  • Time and space complexity analysis
  • Potential follow-up: how to handle very large pi strings or streaming input

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.