Given two binary strings a and b, find the sum of the Hamming distances between a and all contiguous substrings of b of length |a|.
inputCopy:
01
00111
outputCopy:
3
Explanation: For the first sample case, there are four contiguous substrings of b of length |a|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
In this question, i'm only thinking of a brute force solution with time complexity O(|a|.|b|) like a string matching algorithm... Is there any faster algo to do this problem