Description
Solutions
Count Similar Substrings (Microsoft India) π±
π₯ FULLTIMEπRELATED PROBLEMS
A string s
, is similar to another string t
, if it possible to swap two adjacent characters at most once in s
to turn it into t
. Given a keyword string named key
, find how many substrings of text
are similar to key
.
Example 1:
Input: key = "moon", text = "monomon"
Output: 2
Explanation:Consider the first four characters in text. i.e "mono". Swap the last two characters to match the keyword "moon". The last four characters in the text are "omon". Swap the first two characters to match the keyword. Thus, there are 2 substrings of "monomon" that are similar to "moon". Note, that no other substring is similar to the given key.
Example 2:
Input: key = "aaa", text = "aaaa"
Output: 2
Explanation:There are 2 substrings of "aaaa" that are similar to "aaa" are:aaaa aaaa
Example 3:
Input: key = "xxy", text = "zxxyxyx"
Output: 3
Explanation:No explanation is provided for now π©βπΎ
Constraints:
key
andtext
will consist solely of lowercase English letters.1 <= |key| <= |text| <= 50
, where|s|
denotes the length of a strings
.

Related Problems
Testcase
Result
Case 1
input:
output: