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:
- 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 given string is made up of two alternating characters
- Check if a two character string can be made using given words
- 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 whether an array can be made strictly decreasing by modifying at most one element
- 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
- Find the longest string that can be made up of other strings from the array
- Find the character made by adding all the characters of the given string
- N-th character in the string made by concatenating natural numbers
- Generate number with given operation and check if it is palindrome
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.