Mirror String — Asked in Google and De Shaw Interview

Problem Statement :

Given a string S containing only uppercase English characters. Find whether S is the same as its reflection in the mirror.

Sample Input:

ITATI

Sample Output:

Yes

Sample Input:

MZM

Sample Output:

No

Approach :

Check Palindrome and Symmetricity

For a string to be same as its reflection in the mirror, it should satisfy the following conditions:

  1. The given string “S” needs to be a palindrome.
  2. All the characters of the string must be symmetric so that the reflection of the characters remains the same.
  • The symmetric characters are AHIMOTUVWXY.
  • Store the symmetric characters in an unordered set, traverse the string, and if the string contains any non-symmetric character, then return false.
  • If all the characters present in the string are symmetric, then check if the string is a palindrome or not. If the string is a palindrome, then return true, otherwise, return false.

Time Complexity : O(N)
Space Complexity : O(1)

Code :

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

PYTHON: UNIT TESTING

Hybrid Cloud Storage Architecture and Use Cases

Data Processing Quick Guide

Pangeo and Kubernetes, Part 2: Cluster Design

Phase 1 Project Blog

Integrating Stripe

How To Assign Dedicated IPs to OpenVPN Accounts on pfSense

Try Mito Python Package: The Data Scientist’s Spreadsheet

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Longest Increasing Subsequence Coding Question

Live Coding Interviews, simplified with Codejudge.

Live coding interviews by Codejudge

Solve Top LeetCode Problem Smartly

LeetCode Hard DP Problem [Asked in Google]