Given a string S containing only uppercase English characters. The task is to find whether S is the same as its reflection in a mirror.
Input: str = "AMA" Output: YES AMA is same as its reflection in the mirror. Input: str = "ZXZ" Output: NO
Approach: The string obviously has to be a palindrome, but that alone is not enough. All characters in the string should be symmetric so that their reflection is also the same. The symmetric characters are AHIMOTUVWXY.
- Store the symmetric characters in an unordered_set.
- Traverse the string and check if there is any non-symmetric character present in the string. If yes then return false.
- Else check if the string is palindrome or not. If the string is palindrome also then return true else return false.
Below is the implementation of the above approach:
Time Complexity: O(N)
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.
- Check if mirror image of a number is same if displayed in seven segment display
- Check whether two strings contain same characters in same order
- Mirror characters of a string
- Python Dictionary to find mirror characters in a string
- Minimum count of elements required to obtain the given Array by repeated mirror operations
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Print the longest prefix of the given string which is also the suffix of the same string
- Check length of a string is equal to the number appended at its last
- Check if a string has all characters with same frequency with one variation allowed
- Meta Strings (Check if two strings can become same after a swap in one string)
- Check if both halves of the string have same set of characters
- Quick way to check if all the characters of a string are same
- Check if both halves of the string have same set of characters in Python
- Check if two same sub-sequences exist in a string or not
- Check if max occurring character of one string appears same no. of times in other
- Check if a binary string contains consecutive same or not
- Check if a string can be split into two strings with same number of K-frequent characters
- Check whether the string can be printed using same row of qwerty keypad
- Find the count of palindromic sub-string of a string in its sorted form
- Lexicographically smallest and largest anagrams of a string containing another string as its substring
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.