Given two strings a and b, and an integer k which is the index in b at which the character can be changed to any other character, the task is to check if b is a sub-string in a and print out how many times b occurs in a in total after replacing the b[k] with every possible lowercase character of English alphabet.
Input: a = “geeks”, b = “ee”, k = 1
Replace b with ‘k’ and “ek” is a sub-string in “geeks”
“ee” is also a sub-string in “geeks”
Hence the total count is 2
Input: a = “dogdog”, b = “dop”, k = 2
Replace b with ‘g’, “dog” is a sub-string in “dogdog” which appears twice.
Approach: Make a list of all possible versions of the string b by iterating through all the lowercase letters and replacing the kth i.e. b[k] character in b with the current character.
Then count the number of occurrence of the new string b in the original string a and store it in a variable count. After all the lowercase characters are used, print the count.
Below is the implementation of the above approach:
- Count of occurrences of a "1(0+)1" pattern in a string
- Count occurrences of a word in string
- Count substrings with each character occurring at most k times
- Count of number of given string in 2D character array
- Python program to find the most occurring character and its count
- Count occurrences of a string that can be constructed from another given string
- Replace every character of string by character whose ASCII value is K times more than it
- Digital Logic | 5 variable K-Map
- Assign other value to a variable from two possible values
- Replace all occurrences of pi with 3.14 in a given string
- Python | Variable list slicing
- Python | Check if a variable is string
- Find all occurrences of a given word in a matrix
- Check if a binary string has two consecutive occurrences of one everywhere
- Replace all occurrences of string AB with C without using extra space
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.