Given two string S1 and S2, the task is to check whether both the strings can be made equal by performing the given operation on string S1. In a single operation, any character at an odd index can be swapped with any other character at an odd index, the same goes for the characters at even indices.
Input: S1 = “abcd”, S2 = “cbad”
Swap ‘a’ and ‘c’ in S1 and the resultant
string is equal to S2.
Input: S1 = “abcd”, S2 = “abcdcd”
- Create a string even_s1 from the characters at even indices from S1.
- Similarly, generate the strings even_s2, odd_s1 and odd_s2.
- Sort all the four strings from the previous steps.
- If even_s1 = even_s2 and odd_s1 = odd_s2 then print Yes.
- Else print No as the strings cannot be made equal.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check whether two strings can be made equal by increasing prefixes
- Check if two strings can be made equal by swapping one character among each other
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Check if a string is made up of K alternating characters
- Check if a given string is made up of two alternating characters
- Check if a two character string can be made using given words
- Check if one string can be converted to other using given operation
- Check if string can be made lexicographically smaller by reversing any substring
- Program to check if first and the last characters of string are equal
- Check length of a string is equal to the number appended at its last
- Check if count of Alphabets and count of Numbers are equal in the given String
- Check whether an array can be made strictly decreasing by modifying at most one element
- Find the character made by adding all the characters of the given string
- N-th character in the string made by concatenating natural numbers
- Find the longest string that can be made up of other strings from the array
- Check whether an array can be made strictly increasing by modifying atmost one element
- Queries to check whether all the elements can be made positive by flipping signs exactly K times
- Generate number with given operation and check if it is palindrome
- Find the starting indices of the substrings in string (S) which is made by concatenating all words from a list(L)
- Transform One String to Another using Minimum Number of Given Operation
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.