Given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. The task is to make all the strings equal by performing an operation where any character of any of the given strings can be replaced with any other character, print the count of minimum number of such operations required.
Input: A = “place”, B = “abcde”, C = “plybe”
A = “place”, B = “abcde”, C = “plybe”.
We can achieve the task in the minimum number of operations by performing six operations as follows:
Change the first character in B to ‘p’. B is now “pbcde”
Change the second character in B to ‘l’. B is now “plcde”
Change the third character in B and C to ‘a’. B and C are now “plade” and “plabe” respectively.
Change the fourth character in B to ‘c’. B is now “place”
Change the fourth character in C to ‘c’. C is now “place”
Input: A = “game”, B = “game”, C = “game”
Approach: Run a loop, check if the ith characters of all of the strings are equal then no operations are required. If two characters are equal then one operation is required and if all three characters are different then two operations are required.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Minimum characters to be deleted from the beginning of two strings to make them equal
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence
- Make A, B and C equal by adding total value N to them
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Minimum number of given operations required to make two strings equal
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character
- Sort an Array of Strings according to the number of Vowels in them
- Total character pairs from two strings, with equal number of set bits in their ascii value
- Minimum characters to be deleted from the end to make given two strings equal
- Find the minimum number of preprocess moves required to make two strings equal
- Minimum number of operations required to make two strings equal
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Sort the strings based on the numbers of matchsticks required to represent them
- Check if two strings can be made equal by swapping one character among each other
- Check if two strings after processing backspace character are equal or not
- Minimum move to end operations to make all strings equal
- Minimum swaps to make two strings equal by swapping only with third string
- Number of sub-strings that contain the given character exactly k times
- Shortest distance to every other character from given character
- Check whether the given character is in upper case, lower case or non alphabetic character
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.