text and sample. We want to find a place in text where sample appears, possibly with a single typo.
A window is a substring of text with the same length as sample. A window fits if it matches sample in every position except at most one.
Return the start index of the leftmost window that fits, or -1 if there is none (including when sample is longer than text).text="banana", sample="nab" → 2
"ban" differs from "nab" in two places and "ana" in three, while "nan" (from index 2) differs only in its last letter.
text="roses", sample="rise" → 0
The very first window, "rose", differs from "rise" in one letter.
text="abc", sample="xy" → -1
Both windows, "ab" and "bc", differ from "xy" in two places, so the answer is -1.
text="banana", sample="nab"
2
Run checks the first 3 tests in your browser. Submit checks all 137 tests on the server, hidden ones included.