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)
- Mirror characters of a string
- Check if mirror image of a number is same if displayed in seven segment display
- Python Dictionary to find mirror characters in a string
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can be obtained by rotating another string 2 places
- Queries to check if string B exists as substring in string A
- Check if a string can be obtained by rotating another string d places
- Check if a string can become empty by recursively deleting a given sub-string
- Check if a string contains a palindromic sub-string of even length
- Check if a string can be repeated to make another string
- Check whether second string can be formed from characters of first string
- Check if a given string is sum-string
- Check if given string contains all the digits
- Check if a string is substring of another
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.