Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Program to Check Isomorphic Strings. #341

Merged
merged 3 commits into from
Oct 2, 2021
Merged

Added Program to Check Isomorphic Strings. #341

merged 3 commits into from
Oct 2, 2021

Conversation

mahatorakesh
Copy link
Contributor

Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.

Problem

  1. You are given two strings s1 and s2.
  2. You have to determine if they are isomorphic or not.
  3. Two strings are called isomorphic if -
    -> Every character of s1 can be mapped with characters of s2.
    -> A character of s1 can be mapped to only one character.
    -> All occurrences of a character must be replaced with another character while preserving the order of characters.

Solution

  1. If lengths of str1 and str2 are not same, return false.
  2. Do following for every character in str1 and str2
    a) If this character is seen first time in str1,
    then current of str2 must have not appeared before.
    (i) If current character of str2 is seen, return false.
    Mark current character of str2 as visited.
    (ii) Store mapping of current characters.
    b) Else check if previous occurrence of str1[i] mapped
    to same character.

Changes proposed in this Pull Request

  • Program to Check Isomorphic String.

mahatorakesh and others added 3 commits October 2, 2021 12:02
Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
@fineanmol fineanmol merged commit e78ef2e into fineanmol:master Oct 2, 2021
@fineanmol fineanmol added the hacktoberfest-accepted Accept for hacktoberfest, will merge later label Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Accept for hacktoberfest, will merge later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants