1061. Lexicographically Smallest Equivalent String || Leetcode || C++ || Hindi

preview_player
Показать описание
Today we will learn ,how to solve question 1061. Lexicographically Smallest Equivalent String || Leetcode || C++
#leetcode #cpp #dailychallenge #codewithsky #weeklychallenge #preorder #dfs
Рекомендации по теме
Комментарии
Автор

Now am waiting for your next vedios of problem solving 😍

akanksha
Автор

space complexity is O(1) i guess because of constant vector of size 26.
Anyways nice explnation Thanks😊

_shashanks
Автор

Could you please elaborate how the time complexity is (m+n)log(n) ?

This is my first union find question so can't see the logic. Anyway the explanation was concise and to the point. Thanks.

AbhishekVerma-evtv
Автор

You are the Surya Kumar Yadav(SKY) of coding🙏🙏

rskmahesh
Автор

I am also doing a similar way but errror is coming : addition to unsigned offset
class Solution {
public:
char findpar(char node, vector<char>&par)
{
if(par[node - 'a'] == 'node') return node;

return par[node - 'a'] = findpar(par[node - 'a'], par);
}
void merge(char node1, char node2, vector<char>&par)
{
char par_node1 = findpar(node1, par);
char par_node2 = findpar(node2, par);

if(par_node1 < par_node2)
{
par[par_node2 - 'a'] = par[par_node1 - 'a'];
}
else
{
par[par_node1 - 'a'] = par[par_node2 - 'a'];
}
}

string s1, string s2, string baseStr) {
vector<char>par(26);
for(int i=0;i<s1.size();i++)
{
merge(s1[i], s2[i], par);
}
string ans;
for(int i=0;i<baseStr.size();i++)
{
ans = ans + findpar(baseStr[i], par);
}
return ans;
}
};


i am directly passing character in the function of find and merge.

aniketbhura
Автор

bhai tum ashneer grover ki mimicry kr skte ho tumhari aawaz same ashneer se milti h

abhishekgoyalcs_a_
join shbcf.ru