Leetcode 1657. Determine if Two Strings Are Close

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

hi I am not understanding the explanation, it seems like reading the code. could you please explain what the intuition is? thank you!

rabiaaghafoor
Автор

Can you please discuss Leetcode problem 756. Pyramid Transition Matrix .. I am having a hard time understanding it

Phoenix-xigy
Автор

Sir, please make a video on strings all important questions in single video

ayushgarg
Автор

class Solution {
public:
bool closeStrings(string word1, string word2) {
//we dont have solve with bruteforce approach
//u can solve this by by seeing if the frequency of the characters in word1 r same as the frequency of charaacters in word2 (its ok if the freq of the specific char is not same) (property2)
//we have to make sure if the chars r same and no new char is present in 1 string and missing in another (both prop1 and pro2 cant distroy a char hence it will alsoways be there in the string irrespective of the operations u do )

//1st we will find the freq of chars
//we also lable 1 if that char is present or not
vector<int>s1(26, 0), s2(26, 0), s11(26, 0), s22(26, 0);
for(char ch:word1)
{
s1[ch-'a']++;
s11[ch-'a']=1;
}
for(char ch:word2)
{
s2[ch-'a']++;
s22[ch-'a']=1;
}
//we have to sort the frequences so that we can compare easily
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());

return s1==s2 && s11==s22;
}
};

saiei
Автор

There is a better solution in o of n
Why not put all frequencies into two unordered multisets then you can call uset1 quals uset2 it will do it in o1 time and hence overall tc on time

parthapratimghose
Автор

Sir please explain a intuition to solve a problem instead of telling a solution directly

RitikKumar-bkpj