Company: Optiver_4th june_on campus _iit guwahti
Difficulty: medium
Almost Matching You are adding a new operator to a programming language. Any language can test whether two strings match ; yours will also test whether they almost match . Two strings almost match when they have the same length and their corresponding characters are equal at every position except exactly one . For example cat and bat almost match, but cat and dog do not, and neither do cat and cat . To exercise the feature you take a single string s and compare its substrings with one another. Given s and an integer k , count the pairs of substrings of s that almost match and whose one differing character is at 0-based index k of each substring. Precisely, a pair is a choice of two starting indices i < j and one common length L such that L >= k + 1 , and both s[i .. i+L-1] and s[j .. j+L-1] lie inside s (otherwise the substrings would have no k -th character); s[i + p] == s[j + p] for every p with 0 <= p < L and p != k ; s[i + k] != s[j + k] . Count how many such triples (i