Count Substrings That Differ by One Character

Medium

Description

Given two strings s and t, return the count of non-empty substrings of s and t that differ by exactly one character.

Examples

Input:s = "aba", t = "baba"
Output:6
Explanation:

6 valid pairs.

Input:s = "a", t = "a"
Output:0
Explanation:

Edge case with a single character.

Input:s = "abc", t = "def"
Output:9
Explanation:

Since no characters match between s and t, every possible substring pair of the same length will differ by exactly one character. The valid pairs are: (a,d), (b,e), (c,f), (ab,de), (bc,ef), (ac,de), (ab,ef), (abc,def), totaling 9 pairs where each differs by exactly one character.

Constraints

  • 1 ≤ s.length, t.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!