Given two string s1 and s2, the task is to check if characters of the first string can be mapped with the character of the second string such that if a character ch1 is mapped with some character ch2 then all the occurrences of ch1 will only be mapped with ch2 for both the strings.
Input: s1 = “axx”, s2 = “cbc”
‘a’ in s1 can be mapped to ‘b’ in s2
and ‘x’ in s1 can be mapped to ‘c’ in s2.
Input: s1 = “a”, s2 = “df”
Approach: If the lengths of both the strings are unequal then the strings cannot be mapped else create two frequency arrays freq1 and freq2 which will store the frequencies of all the characters of the given strings s1 and s2 respectively. Now, for every non-zero value in freq1 find an equal value in freq2. If all the non-zero values from freq1 can be mapped to some value in freq2 then the answer is possible else not.
Below is the implementation of the above approach:
- Remove all occurrences of a character in a string
- Count occurrences of a character in a repeated string
- Print the string by ignoring alternate occurrences of any character
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Replace every character of string by character whose ASCII value is K times more than it
- Modify the string such that every character gets replaced with the next character in the keyboard
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of a string by a different character
- Check if all occurrences of a character appear together
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Printing frequency of each character just after its consecutive occurrences
- Minimize ASCII values sum after removing all occurrences of one character
- Find the number of occurrences of a character upto preceding position
- Count substrings that starts with character X and ends with character Y
- Longest Common Prefix using Character by Character Matching
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.