Find the First Almost-Equal Substring
Problem statement
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) → intExamples
Example 1
s = "abcdefg"pattern = "bcdffg"return = 1bcdefg differs from bcdffg in one position.
Example 2
s = "ababbababa"pattern = "bacaba"return = 4bababa begins at index 4 and differs from the pattern once.
Example 3
s = "abcd"pattern = "dba"return = -1Every length-three substring differs in more than one position.
Constraints
1 <= pattern.length < s.length <= 100000.sandpatterncontain only lowercase English letters.