I usually don't watch videos more than 15 mins but yours is the only one where I watch without any limits.
@codestorywithMIK Жыл бұрын
It means a lot ❤️
@molyoxide8358 Жыл бұрын
@@codestorywithMIK TYSM
@alphonseprakash74592 ай бұрын
i figured out the same approach even without seeing the video 😅. I guess I am getting better at graph and the credit goes to you playlist.
@iamnoob75933 ай бұрын
Mik , This is a fabulous explanation , Again a tough problem.
@anuppatankar4294 Жыл бұрын
After watching your explanation, I coded it myself👍🏻
@codestorywithMIK Жыл бұрын
We all are growing together. That’s all i want ❤️💪
@anuppatankar4294 Жыл бұрын
@@codestorywithMIK Yes bro 🤝🏻🔥
@souravjoshi2293 Жыл бұрын
Bhai, you are an example of perfection
@souradeep.23 Жыл бұрын
Thank you💥. Can you upload a solution for this based on DSU please ?
@codestorywithMIK Жыл бұрын
Let me think about DSU for this. I like that we are now curious about DSU. Thanks for asking. Will definitely check DSU
@vaibhavgupta973 Жыл бұрын
thank you ! this was a really interested question . learned something new from this problem today !!
@codestorywithMIK Жыл бұрын
Indeed ❤️👍🏻
@xiaoshen194 Жыл бұрын
Ramzan Mubarak Bhai. Thank u for ur efforts 🙏
@codestorywithMIK Жыл бұрын
Ramzan Mubarak ❤️
@ankitagrahari74533 ай бұрын
Genius🙌
@AnjuGupta-sz1uk7 ай бұрын
Awesome explanation 😀
@ayush_243 ай бұрын
10:45 kaash zindegi main bhi aise he pata chal jaata 🥲🥲
@rahulmaurya6451 Жыл бұрын
Great Explanation as always ❤
@codestorywithMIK Жыл бұрын
Thanks a lot Rahul ❤️
@shikharpandya49276 ай бұрын
great explaination
@aryanbhardwaj75192 ай бұрын
this is next level easy
@tutuimam3381 Жыл бұрын
Thanks a lot🌹
@035-harshitsingh7 Жыл бұрын
bhaiya jb bhi minimum path se related ho to to bfs ke baare me sochne bola tha yha dfs se kyun kr rhe hain hm?? BFS se bhi to kr skte hain na
@codestorywithMIK Жыл бұрын
Yes you can solve it using BFS also. And must solve it first by BFS
@codestorywithMIK Жыл бұрын
Wow. Thanks a lot for sharing ❤️❤️
@thegreekgoat98 Жыл бұрын
Saw first 10 minutes of this video, and able to code myself. But I have a doubt, is it feasible to have this much of time and memory (one that you see after a submission in leetcode)??
@codestorywithMIK Жыл бұрын
Comments like these make me so happy
@thegreekgoat98 Жыл бұрын
@@codestorywithMIK is it feasible to have this much of time and memory (one that you see after a submission in leetcode)??
@fashionvella730 Жыл бұрын
its time complexity is same as normal DFS nothing more than that O(V+E)
@Ramneet04 Жыл бұрын
What if there is a edge between 2 and 5 how will it work?? How we can have parent as it will become a cycle
@rev_krakken708 ай бұрын
What a nice explanation, however this intuition looks simple but kind of hard to come by. How did you come up with this?
@doingit621 Жыл бұрын
plz keep posting daily
@codestorywithMIK Жыл бұрын
Sure thing 👍🏻💪
@doingit621 Жыл бұрын
@@codestorywithMIK can u share ur linkedin?
@sarveshjoshi69136 ай бұрын
same Qn in microsoft OA today😥
@aakshatmalhotra8088 Жыл бұрын
for traversal in undirected graph we only need parent not the visited vector?? Is this right (or is it only true for tree)?
@iamnoob75933 ай бұрын
parent is for tree only.
@ALOKKUMAR-sd6bn3 ай бұрын
this solution will not work for test case [[0,1],[1,2],[3,2],[3,5],[5,4],[0,4]] this test case is not present on leetcode but it will not work for this . problem is: we blindly increasing count+1 whenever we finding the check==1 but there will be possibility that we will reach to end city by another path , that thing is missing here. bhaiya , am i correct?
@gaurimandot5788 Жыл бұрын
C++ code class Solution { private: void dfs(unordered_map &adjList,int node,vector&vis,int &flip){ vis[node]=true; for(auto i:adjList[node]){ if(vis[i.first]==false){ if(i.second==1){ flip++; } dfs(adjList,i.first,vis,flip); } } } public: int minReorder(int n, vector& connections) { //Hum routes ko bidirectional bana rahe hai //1 weight for asli route //0 weight for nakli route //dfs traversal karenge //agar u->v hum asli route se jaa paa rahe hai matlab v->u hume nakli route se aana padega //Hence uss route ko flip karna hoga unordered_map adjList; for(int i=0;i
@thegreekgoat98 Жыл бұрын
is it feasible to have this much of time and memory (one that you see after a submission in leetcode)?
@codestorywithMIK Жыл бұрын
It is fine for a problem like this. Because if you notice we are doing DFS only which is the ultimate solution since you have to travers the graph anyways. And for this problem, I believe there is no way to solve this without introducing extra edge and storing pair value in adjacency list. But I’ll explore more possibilities for this
@thegreekgoat98 Жыл бұрын
@@codestorywithMIK Got it. thanks for replying.
@ShivamGupta-cx3hy Жыл бұрын
thank you''' so much
@vikneshcsАй бұрын
What if cycle is present
@prajwalshaw9217 Жыл бұрын
Sir is the tc of this question..O(v+2e)...and sc is O(1)..?
@Whirlwind03 Жыл бұрын
What an explanation brotha nailed it. // Java Code class Solution { // here type if 1 indicates that its an original edge that is given in connections array. // type if 0 indicates that its not an original edge and created manually to connect the graph. public class Edge{ int nbr; int type; public Edge(int nbr,int type){ this.nbr = nbr; this.type = type; } } private ArrayList[] graph; private int result; public void dfs(int src,int parent){ for(Edge edge:this.graph[src]){ int nbr = edge.nbr; int type = edge.type; if(nbr != parent){ if(type == 1){ this.result+=1; } dfs(nbr,src); } } } public int minReorder(int n, int[][] connections) { this.graph = new ArrayList[n]; this.result = 0; for(int i=0;i
@alphagaming5432 Жыл бұрын
linked list series bhi lao basic se boht basic se
@codestorywithMIK Жыл бұрын
Noted . Currently there is a linked list playlist for Qns. I will create another one for basics and from beginning for LinkedList
@manimanohar_001 Жыл бұрын
Again first view today.
@alphagaming5432 Жыл бұрын
i was first
@manimanohar_001 Жыл бұрын
@@alphagaming5432 i think you missed it
@alphagaming5432 Жыл бұрын
@@manimanohar_001 no way
@manimanohar_001 Жыл бұрын
@@alphagaming5432 don't bother a lot Buddy
@abhiverma5135 Жыл бұрын
27:31 why you put & after auto keyword inside for loop what it'll do??
@codestorywithMIK Жыл бұрын
Hi abhi, Putting an “&” helps to avoid creation of extra copy of any variables. It’s called as “reference” You can refer to this link to get to know more about this : stackoverflow.com/questions/12728794/why-should-i-use-reference-variables-at-all
@abhiverma5135 Жыл бұрын
@@codestorywithMIK okay so you mean the &vec we are using in loop is referring to the same location where actually values are stored in the memory... Right?
@codestorywithMIK Жыл бұрын
Exactly abhi. It helps to save time (because no copy is created) . But be cautious because, if you change vec, it will change original value.
@abhiverma5135 Жыл бұрын
@@codestorywithMIK okay thank you so much😄😄
@prudhvirajmacherla9854 Жыл бұрын
Hero
@nish07989 ай бұрын
class pair { int dest; int typeofedge; public pair(int dest, int typeofedge) { this.typeofedge = typeofedge; this.dest = dest; } } class Solution { static int count = 0; public int minReorder(int n, int[][] connections) { boolean[] vis = new boolean[n]; ArrayList gra = new ArrayList(); for (int i = 0; i < n; i++) { gra.add(new ArrayList()); } for (int[] c : connections) { int src = c[0]; int dest = c[1]; gra.get(src).add(new pair(dest, 1)); // real edge gra.get(dest).add(new pair(src, 0)); // fake edge we created } for (int i = 0; i < n; i++) { if (vis[i] == false) { dfs(gra, i, vis); } } return count; } public void dfs(ArrayList gra, int i, boolean[] vis) { vis[i] = true; for (pair nbr : gra.get(i)) { int dest = nbr.dest; int type = nbr.typeofedge; if (vis[dest]==false) { if (type == 1) { count++; } dfs(gra, dest, vis); } } } } @codestorywithMIK bro ye code maine likha after watching your video but ye errror de raha hai please tell what is issue please reply
@chiragahuja4727 Жыл бұрын
god or what you are .. damn
@codestorywithMIK Жыл бұрын
🙏🙏❤️😇
@kanhaiyasulay88097 ай бұрын
There was no need to check for the parent
@udaykumarchetla6205 Жыл бұрын
Bro u hv leetcode premium?
@codestorywithMIK Жыл бұрын
No Uday.
@shivamsharma-oi3gn7 ай бұрын
Why It is giving TLE for this code : class Solution { public: void DFS(int node, int parent, unordered_map adj, int &ans){ for(auto i : adj[node]){ int vertex = i.first; int check = i.second; if(vertex != parent){ if(check == 1) ans++; DFS(vertex, node, adj, ans); } } } int minReorder(int n, vector& connections) { unordered_map adj; for(auto i : connections){ int u = i[0]; int v = i[1]; adj[u].push_back({v, 1}); adj[v].push_back({u, 0}); } int count = 0; DFS(0, -1, adj, count); return count; } };