Given a sorted Dictionary of an Alien Language, find order of characters | [Explaination + CODE] 🔥
Vložit
- čas přidán 6. 09. 2024
- #graph #competitiveprogramming #coding #dsa
Hey Guys in this video I have explained with code how we can solve the problem 'Given a sorted Dictionary of an Alien Language, find order of characters'.
Join our Telegram Channel for more Information
🔰 Telegram Channel Link = t.me/CodeLibrary1
🔰 Array question Playlist = • Love Babbar DSA 450 Qu...
🔰 String question Playlist = • Love Babbar DSA 450 Qu...
🔰 Searching and Sorting question Playlist = • Love Babbar DSA 450 Qu...
🔰 Binary Tree question Playlist = • Love Babbar DSA 450 Qu...
🔰 Dynamic Programming question Playlist = • Love Babbar DSA 450 Qu...
🔰 RoadMap of Web Development = • 🔴 Web Development Road...
🔰 Roadmap for Dynamic Programming = • Complete Roadmap for D...
🔰 Great Strategy to solve DSA = • Great Strategy to solv...
🔰 My Journey to 5 star at codechef = • My Journey to 5 Star a...
🔰 Love Babbar DSA Sheet : drive.google.c...
Follow us on Instagram:
🔰 Shailesh Yogendra : / shaileshyogendra
🔰 Yogesh Yogendra : / i_am_yogesh_here
Follow us on LinkedIn:
🔰 Yogesh Yogendra : / yogesh-yogendra-26bbb518a
🔰 Shailesh Yogendra : / shailesh-yogendra-8b13...
Hope you like it. Comment if you have any doubt
LIKE | SHARE | SUBSCRIBE
bro digital drawing pad aata hai. Wo buy kar le, I'll be good for you to explain and write.
Great explanation...was trying to do this question since long
ba , dc
Iska graph kaise bnega bhai , is code k hisab se to bs b->d hi create hoga , a or c ka kya hoga ?????
you explain brilliantly .
Excellent explanation!!
Toposort as to be start with a node with degree 0( means no incoming edge).....
We start with indegree 0 in BFS (Kahn's Algorithm) but in DFS you can start from anywhere
Great explanation brother! If possible please also provide a link to your source code!
thanks for explaining question so well
nice explanation
You are very hurry in a main coding part.
How to approach that is very good explanation but you have to focus more deeply on code.
Your code is not working bro
Shouldn't we compare every pair of strings rather than just consecutive ones?
i have the same query that why are'nt we comparing all pairs? @CodeLibrary
the list is already sorted, so we could traverse through pair of words and build graph.
Great explanation
Plz make video on " Tarjans Algorithm for SCC"
Great Explanation
Hello bhaiya...I am writing the same code in java...but I am getting "IndexOutOfBoundException" error....please tell me how to solve this
class Solution2
{
public String ans = "";
public String findOrder(String [] dict, int N, int K) {
// Write your code here
ArrayList graph = new ArrayList();
for(int i = 0; i < K; i++) graph.add(new ArrayList());
for(int i = 0; i < N -1; i++) {
String wd1 = dict[i];
String wd2 = dict[i + 1];
for(int j = 0; j < Math.min(wd1.length(), wd2.length()); j++) {
if(wd1.charAt(j) != wd2.charAt(j)) {
graph.get(wd1.charAt(j) - 'a').add(wd2.charAt(j) - 'a');
break;
}
}
}
boolean[] vis = new boolean[K];
for(int i = 0; i < K; i++) {
if(!vis[i]) dfs(i, graph, vis);
}
return ans;
}
public void dfs(int i, ArrayList graph, boolean[] vis) {
vis[i] = true;
for(int x : graph.get(i)) {
if(!vis[x]) dfs(x, graph, vis);
}
char ch = (char)(i + 'a');
ans = ch + ans;
}
}
This code is giving TLE.Please help
greaaaaaat explanation!
What about this test case ?
{"bac", "bad", "baefgh"}
graph will look like : c -> d -> e
and the topo sort is : c, d, e
But where is f, g, h in the order ????
HELP PLEASE !
did the question state that you need to tell order of all k char, not right.
And this also depends on n and k like as in your test case k is 6 and n is only three so not possible to state order for all k, u need atlest k words if each specify the order of letter else you need more words.
@@raunakkumar6144 Ohh! understood.
Thank you so much for explain.
when using your solution, I am getting and in reverse. why?
Bhai graph g(k) ke liye vector of vector kyun liya ek se bhi kaam ho sakta hai na
nahi bhai , adjacenecy list hai na , har letter ke arrow pe kaun kaun hai wo to ek matrix ban jayega
@@ankitdubey9310 Thanks
Bhai ek bar kruksal aur prim's ki bhi video banado.It's difficult to understand code
Watch take you forward video its good
Segmentation fault is coming
void dfs(int src,vector &g,vector &vis,string &ans)
{
vis[src] = 1;
for(auto x:g[src])
{
if(!vis[x])
{
dfs(x,g,vis,ans);
}
}
char ch = src + 'a';
ans = ans + to_string(ch);
}
string findOrder(string dict[], int N, int k) {
//code here
vector g(k);
for(int i=0;i
@@nishantmittal1506 return ans ;
@@nishantmittal1506 Still facing the same problem
@@rahulbanerjee9676 no bro ab tou placement bhi hogi
check your loop you must have been lopping it for n instead of n-1
any one having code for this
Bhai Graph ke baad Start Bst please.
no need beacuse it is already in sorted order
Believe me or not you guys explain much better than striver.
Thanks brother...♥♥♥
LOL😂
Lol 🤣🤣🤣
Explanation is not better than striver but this guy is not business minded as striver.