Given two strings S1 and S2 ( size of S1 <= Size of S2 ). The task is to find the minimum number of characters to be replaced in the string S2, such that the string S1 is a substring of S2.
Input : S1 = cdef, S2 = abbdef Output : 1 Input : S1 = gfg, S2 = fgg Output : 2
- Traverse the string S2
- From every index in S2, check the number of mis-matching characters in substring of length of S1
- Store and update the minimum of prev and current mis-match in ans
- Return ans.
Below is the implementation of the above approach:
Time Complexity: O(N * M).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum changes required such that the string satisfies the given condition
- Minimum flips required to form given binary string where every flip changes all bits to its right as well
- Longest Even Length Substring such that Sum of First and Second Half is same
- Minimum changes to a string to make all substrings distinct
- Find the character in first string that is present at minimum index in second string
- Maximum length substring having all same characters after k changes
- Lexicographic smallest permutation of a String containing the second String as a Substring
- Minimum length of substring whose rotation generates a palindromic substring
- Minimum flips required in a binary string such that all K-size substring contains 1
- Minimum substring flips required to convert given binary string to another
- Make a lexicographically smallest palindrome with minimal changes
- Minimum size substring to be removed to make a given string palindromic
- Count subsequences in first string which are anagrams of the second string
- Most frequent word in first String which is not present in second String
- Count of times second string can be formed from the characters of first string
- Remove characters from the first string which are present in the second string
- Check whether second string can be formed from characters of first string
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Minimum swaps required to make a binary string alternating
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.