Isomorphic Strings Leetcode Solution
Vložit
- čas přidán 19. 10. 2020
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the Isomorphic Strings problem using hashmaps in java. In this 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.
Note - Length of s1 is equal to the length of s2.
To attempt and to submit this problem, click here: www.pepcoding.com/resources/d...
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
#hashmaps #datastructure #algorithms
Have a look at our result: www.pepcoding.com/placements
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
who are these people who disliked very simple explanation. Thank you for the brilliant explanation. 🙏
The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating and Keep loving😊
@@Pepcoding Yes not even single video, whenever i search any video and if i find you've given explanation on that, dusri video open karne ka sawal hi nahi hota.
👌🏻
@Pepcoding I also agree with@@Rahul0508-n9m . I really appreciate your explanation.
Best explanation,covering all edge cases
how in line 26 map2.put(ch2, true) is working it should be ch1 in place of true otherwise it will show error of boolean cannot be converted to Character
Thank You Sir!, 290. Word Pattern question was asked to me in Zoom interview (San Francisco). I did same mistake of not mapping bidirectional. Thanks for clarification.
Always there for you guys. for better experience and precisely arranged content visit on nados.pepcoding.com
Don't forget to follow us on Instagram instagram.com/pepcoding/
what if there was a character from str1 in str2 , like there's an 'a' instead of 'z' in str2. Now, 'a' would be mapped with 'x' and 'c' would be mapped with 'a'. So its not a one to one relation.
your explanations are awesome!!! I don't understand why your videos are underrated.
Because motivational gyan videos are over rated
after watching 2-3 videos of FAANG ytubers, I land up on this. Thanks
Amazing explanation, Sir 🥰
Thanks Sir for explaining beautifully :)
Wonderful expalanation!
Thank you for amazing expanation sir
you are great!! I can't even watch other youtubers videos now..
//Thank You Sir, your hint helped me a lot . The examples in certain platforms are just hillarious
int n=str1.size();
int m=str2.size();
if(n!=m)return false;
maptwo;
mapumap;
for(int i=0;i
@Pepcoding paper and title is isomorphic string as per leetcode, but as per your code its not isomorphic.
this code is working fine in all scenarios except the below Test case.
String s1 = "paper";
String s2 = "title"
can someone give a try.
Its because the 'e' in both are considered different. If we assume it to be same then this solution will fail.
For that you need to have two hashmaps and see the one on one mapping
Sir HashMap ke bade tricky questions lagte the mujeh pehle, saare ratte wale, lekin acquire and release strategy se arram se ho gye, no need of cramping, 1 din mein 25 questions acquire and release se ho gye, great strategy
haina? Jab full 100 ho jaenge tab bhot sare array and strings ke questions bhi ho chuke honge
Very Nice explanation...
Good job 👍
Sir in your solution you have used two Hashmaps, I have solved with one HashMap (for character to character mapping ) and one HashSet( for checking the test cases when same character of string t is mapped to different characters of string s ).
Which one of the two solutions(in terms of data structure and complexity) will be better ?
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
HashSet internally uses HashMap. So TC will be same
yeah ,checking for boolean is same as contains check
You can use a hashset as well as a pool of chars which r already seen
sir test cases strong nhi hai portal pr
a b b a
dog dog dog dog
iske lie correct de rha hai update kr do
what is tc and sc ?
Very Nice Explanation.....Keep making videos
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Sir can you please provide the interview prep list currently being used in classroom courses at pepcoding.
beta level2 mei latest aa jaega sab.
@@Pepcoding sir wo to theek hai lekin levelup k questions leetcode p search karne m bahut dikkat hoti hai . Isliye mai kh rha tha ki leetcode based ek list de dijiye jisse questions dhoonde na pade baar baar . Aur sir aap bhi kehte ho ki acche test cases k liye leetcode p submit maar liya karo.
@@gauravsharma5768 ok beta, thoda time dedo firr. Mil jaegi list.
@@Pepcoding thank you sir , bahut jarurat hai uski
@@gauravsharma5768 telegram group join kar lo uss pe aur bhi material aata rehta hai
can we solve this without map?
why this is not working
unordered_maps;
for(int i=0;i
In this question can't we use group shifted method?
For better insight, visit nados.pepcoding.com, post your doubts, community will help you out there.
Sir pepcoding ke videos CZcams pe Kab tak available rahenge?
hmesha beta.
if (map.containsKey(chS)) {
if (map.get(chS) != chT)
return false;
} else {
if (map.containsValue(chT))
return false;
map.put(chS, chT);
} sir hamlog ek map se bhi kar skate hai ki agr chS conatins karta hai to vo chT hi hoga and agar nahi karta hai to
ye checkKar lenge ChT ka value alreafy hai ki nahi
Thank you sir 🙏🙏. Sir graph level up upload kijiye please 🙏🙏
As soon as possible
bool isIsomorphic(string s, string t) {
map mp;
for(int i=0;i
addicted to pepcoding
Keep learning
s1="title" t1="paper" how is isomorphic explain?
Awesome
Glad to know. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
There is no need of two HashMaps here. It can easily be done using one HashMap
I am trying my best to increase the subscribers of this amazing channel..❤️❤️❤️❤️🙏
Thankyou for supporting.
Keep learning.
And for better experience and well organised content visit nados.pepcoding.com
I think we can solve it by using two hashmap of character vs character
Sir why there is so much negativity about service based companies? Does life end in infy, accenture, tcs, etc?
arey nahi. sabko product based company chaie bass. as such mujhe to service based company mei project change karne ki possibility ki wajah se jyada learning dikhti hai
@@Pepcoding is it good to join a services based company with 2 years bond.
@@himanshushekhar3304 nope
kya cheez ho yr tum sir...kitna acche se batate ho..
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
czcams.com/users/Pepcodingabout?view_as=subscriber
@@Pepcoding review done sir
🥇😁😁
best paart 5:28 to 5:31
paper
title
sir is case ka answer kya hona chaiye .......... expected answer "true" de rkha h but 'e' agar 'l' ke saath map h to 'r' 'e' ke saath map nhi hona chaiye
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. Therefore, we have a premium facility available for the students in which you can get the 12 hours doubt support facility. Jisme aap agr kisi bhi question main kahin bhi faste ho to aap doubt support par reach kar skte ho aur aapko TA assign ho jayega and you can get your doubt resolved from them.
@@Pepcoding ok sir,thank u
E doosri string waala hai is baar
sir appp accha gana gate hai1
One of the edge cases is still failing here, try this solution with "baa" and "cfa".
best
Glad you liked it!
Keep learning
And for better experience, visit nados.io, where you will get well curated content and career opportunities.
Aur kitne questions hai hashmap ke ????
70 more
class Solution {
public boolean isIsomorphic(String s, String t) {
if(s.length() != t.length()){
return false;
}
HashMap map = new HashMap();
for(int i = 0; i < s.length(); i++){
char sChar = s.charAt(i);
char tChar = t.charAt(i);
if(map.containsKey(sChar)){
if(map.get(sChar) != tChar){
return false; // Mismatch found
}
} else {
if(map.containsValue(tChar)){
return false; // Mapping already exists for another character
}
map.put(sChar, tChar); // Establishing mapping
}
}
return true;
}
}