FastPrepFind the First Almost-Equal Substring
Problems/Find the First Almost-Equal Substring

Find the First Almost-Equal Substring

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report points to the well-known problem Find the Occurrence of First Almost Equal Substring. Our version keeps its rules exactly: at most one mismatch, and the smallest start index.

You are given lowercase strings s and pattern.

Two equal-length strings are almost equal when changing at most one character in the first can make them identical. Return the smallest starting index of a substring of s that is almost equal to pattern. Return -1 when no such substring exists.

Function

minStartingIndex(s: String, pattern: String) → int

Examples

Example 1

s = "abcdefg"pattern = "bcdffg"return = 1

bcdefg differs from bcdffg in one position.

Example 2

s = "ababbababa"pattern = "bacaba"return = 4

bababa begins at index 4 and differs from the pattern once.

Example 3

s = "abcd"pattern = "dba"return = -1

Every length-three substring differs in more than one position.

Constraints

  • 1 <= pattern.length < s.length <= 100000.
  • s and pattern contain only lowercase English letters.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 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
  • 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

  • Deterministic Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Longest Word Containing Another InputMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Word Search IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions

Interview reports that mention this question

  • Google PhD AI/ML New Grad Coding Onsite: 1 Experience

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minStartingIndex(String s, String pattern) {
        // Write your code here.
    }
}
Checking account…