Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
Vložit
- čas přidán 24. 07. 2024
- Whatsapp Community Link : www.whatsapp.com/channel/0029...
This is the 28th Video of our Playlist "Leetcode Easy".
In this video we will try to solve an easy map Problem :
Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
Company Tags : LinkedIn
My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/isomorp...
Approach Summary :
This code implements a solution to determine whether two given strings, 's' and 't', are isomorphic. Isomorphic strings are those that can be mapped to each other by replacing characters while preserving the order.
The approach involves using two unordered maps, 'mp1' and 'mp2', to store mappings from characters in 's' to characters in 't', and vice versa, respectively. It iterates through the characters of both strings simultaneously. For each pair of characters, it checks whether the mappings stored in 'mp1' and 'mp2' conflict with the current characters. If there is a conflict (i.e., if the mappings are inconsistent), it returns false, indicating that the strings are not isomorphic. If no conflict is found after iterating through all characters, it returns true, indicating that the strings are isomorphic.
Overall, the approach efficiently determines whether the given strings are isomorphic by maintaining mappings between corresponding characters and checking for conflicts.
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My Sliding Window Playlist : • Count Occurrences of A...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
3:42 - Thought Process
6:47 - Corner Case Example 1
12:21 - Corner Case Example 2
15:04 - Coding it up
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
what an amazing expaliation
thank you bhaiyaa , corner cases dekhke hi samaj gaya kaha code phassa tha mera .
I subsrcibed your channel 8 month ago and the energy of teaching remains the same.
nice. I also failed the same test case and then figured out the problem.
Thank you sir for sharing your important time with us ❤
kaafi tricky Problem statement tha. thanks for making it easy
Thanks a lot bhaiya ❤❤
Thanks a lot
Solved it on my own
Came here to learn optimisation
Thanks :)
Thank you ☺️
You are lovely mik ....thanks
nice one
Java code guyz...
class Solution {
public boolean isIsomorphic(String s, String t) {
int n=s.length();
int m=t.length();
if(n!=m) return false;
HashMap mp=new HashMap();
for(int i=0;i
thanks
Thanks
even i tried using map, and mapped the frequency of both the strings. Then iterated over a string to to check any mismatch in frequency. passed 43/45 testcases. got stuck at the preserving order point , which was i guess the crux of the problem. thanks for solution
🔥🔥🔥🔥🔥
@ codestorywithMIK bhaiya ye orthogonal greedy algo ka question kaha se kare and pattern of this question
can we use the find function in such a way that when we are searching for the first string element we can also check if the associated elements with it also exists or not
I was able to solve this 🙂
november se ye question ko 6 attempt ho gye the wrong submission k..lfinally aaj clear hua
Bro pls
Longest substring with atleast k repeating character ka ek video bana do
Sir can you tell me which editor do you use while explaining?
It is really very clear explanation. Thank you.
Apple notes hain ipad mein inbuilt hota hain
Can you give a solution using bit manipulation??
i have a doubt will there a problem if length of s and t are different????
10:22 kya hum ek hi map me value ke through key ko ni check kr skte? Jaise key se value check kr rhe? 🤔
No, because we need something to distinguish that the character I see in the map belongs to s or t
Another approach but same space and time complexity :)
bool f(string s,string t){
int size1=s.size(),size2=t.size();
if(s==t) return true;
unordered_mapmp;
unordered_maptaken;
for(int i=0;i
Why 256 as size ( when both capital and small letters are their ). i could understand 60(65-124). Please tell me
In ASCII, for example, there are 128 characters, but if you include extended ASCII, there are 256 characters. This includes both uppercase and lowercase letters, digits, punctuation marks, and control characters. So, to ensure that you can handle both lowercase and uppercase letters, you might use an array size of 256 to cover all possibilities.
man, this question confused the hell out of me.
if some one want a simple solution with not many condition are -
class Solution {
public:
bool isIsomorphic(string s, string t) {
vectormark(257,false);
vectorc(257,' ');
for(int i = 0;i
sir, here we are taking 2 additional maps right? So how the space complexity is still 0(1) ?
With 2 additional maps, its O(2 x 1(for limited characters)) so = 0(1).
Because the constraints says that there will be only valid ascii characters in the string. We have only 256 ASCII characters. so map size will never exceed 256. Hence constant.
s and t consist of any valid ascii character.
class Solution {
public void create(char[]arr){
char start='a';
char[]mp=new char[256];
for(int i=0;i
class Solution {
public:
bool isIsomorphic(string s, string t) {
int sn = s.size();
int tn = t.size();
if(sn != tn){
return false;
}
unordered_map mp;
vector ta(128, false);
for(int i = 0; i < sn; i++){
char sc = s[i];
char tc = t[i];
if(mp.find(sc) == mp.end()){
if(ta[tc] == true){
return false;
}
mp[sc] = tc;
ta[tc] = true;
}
else{
if(mp[sc] != tc){
return false;
}
}
}
return true;
}
};
s = "paper", t = "title", 'e' is alreday mapped with ''l' and and 'r' is mapped with 'e'? 2 different character mapped with same character?
(e->L ) making pair in hash1. (L->e) making pair in hash2.
now (r->e) making pair in hash1 and (e->r) in hash2.
are you noticed that, "e" not appear in hash2 before, where you adding now .
"e" as a key existing in different hash
hash1 hash2
e-->L L-->e
r-->e e-->r
@@HossainAhmedSiam-ot5jr thanks bro
What if string s= "abc" and string t="bas"??
a -> b
b -> a
c -> s
No same character in s is matched with different characters in t. So it's true.
sir yee approach me kya galati haii
mapmp1,mp2;
int n=s.size();
vectorv(256,1);
for(int i=0;i
You haven’t uploaded this map code in github repo rather you have added the same arraylist code twice. Pls modify.
Done ❤️
kyaa haal h bhai ( aap software engineer ban jaun na ...paise chhapo daba ke) khair fir yt mat choddna (LG jayenge fur mere)
@codestorywithMIK #codestorywithMIK
Thank you bhaiya to make difficult question, easy.
Would you please make the video for this question czcams.com/video/2ISNCDJEgqQ/video.html
As the solutions available for this is very less, and also complicated.
Hope to get the solution for this question soon.
Thank you so much for giving time to read this and think about it.
bhai yeh link toh issi video ka hai
link is of this video only
thank you for existing
Important Substitue:
I think we can Replace Map2 with unordered_set. It can work.
Here is the updated code:
class Solution {
public:
bool isIsomorphic(string s, string t) {
int n = s.size();
unordered_map mp;
unordered_set mapped;
for (int i = 0; i < n; i++) {
if (mp.find(s[i]) == mp.end()) {
if (mapped.find(t[i]) != mapped.end())
return false;
mp[s[i]] = t[i];
mapped.insert(t[i]);
} else {
if (mp[s[i]] != t[i])
return false;
}
}
return true;
}
};