LeetCode: Isomorphic Strings

Thank you for visiting this post! Be sure to also take a look at my other work on LinkedIn, Github, and my website.

Taking a look at another Algorithm this week, we’re tackling Isomorphic Strings. What are they and how in the world can we determine if the strings we have are Isomorphic or not? Let’s look at the definition below and get started:

“Two strings, X and Y , are called isomorphic if all occurrences of each character in X can be replaced with another character to get Y and vice-versa. For example, consider strings ACAB and XCXY .”

(Techiedelight.com)

Problem

Please click the link below to view the Problem Statement

Solution

My solution was the following:

Although my solution worked, it was not very fast on the time complexity spectrum. As always, here is a faster, optimal, one liner solution.

Using the spread operator, mapping through each element of the string and comparing the index to the other string. Genius!

Conclusion

Thank you so much for stopping by! Stay tuned for more Algorithm Content!

Please checkout my online portfolio and feel free to connect with me on Linkedin!

Sources:

https://www.techiedelight.com/isomorphic-strings/#:~:text=Two%20strings%2C%20X%20and%20Y,consider%20strings%20ACAB%20and%20XCXY%20.

https://leetcode.com/problems/isomorphic-strings/discuss/285805/One-line-JavaScript-Solution

--

--

--

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

Recommended from Medium

10 JavaScript Array/Object Tricks

Mock Test in React with Jest

Making a User Media Preview Component

A short Introduction to ReactJS, A JavaScript Framework

Setup React-Native Font: The Easy Way

Nike Air Zoom Wildhorse 3 GTX https://t.co/ta4QAUPNLE https://t.co/l669WbOUjk

React Hooks — A Conceptual Overview

Node.js REST API with RBAC, JWT, Repository and MVC pattern. Part 3.

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
Stephanie Segura

Stephanie Segura

More from Medium

Snakes and Ladders (Leetcode 909)

Inheritance Quiz

k-ary tree in MySQL

Interview Preparation Series