Isomorphic String in JavaIt is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, Uber, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to discuss what is isomorphic string and how to check if the string is isomorphic or not with different approaches and logic. Also, we will create Java programs for the same. Isomorphic StringThe string is called isomorphic if the letters of the one string can be mapped to get the second string. Mapping means replacing all occurrences of a letter with another letter but the ordering of the letters remains unchanged. Note that no two letters may map to the same letter but a letter may map to itself. Let's understand it through examples. Example 1: Suppose, string1 is ABACB and string2 is XPZ. Now map string1 to string2.
Replace A -> X, B -> P, A -> X, C -> Z, B -> P. Hence, we observe that string1 and string2 are isomorphic to each other. Let's see another example. Example 2: Suppose, string1 is PQPRQP and string2 is XPZW. Now map string1 to string2.
Replace P -> T, Q -> U, P -> T, R -> V, Q -> U, P -> W. Hence, we observe that string1 and string2 are not isomorphic to each other. Algorithm
Let's implement the above algorithm in a Java program. Java Program to Check if the Two Strings are Isomorphic or notIsomorphicString.java Output: Are KITE and ZXBN Isomorphic? true Next TopicJava ImageIO Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India