Sir itna shandar ques one go mein code karne laayak samjha diya aapne sir. This is the power of teachers at pepcoding. Baaki channel bas code walkthrough karwate. Kaise sochke code likhna hai wo to aap hi ne sikhaya hai sir..thanks team pepcoding 😁
Hi Subhesh, You have a very good Skill of Explaining things on top of your exceptional Algorithmic Knowledge and covering the point where one might get doubts in. I hope you will keep adding videos to this series, at this point of time, I am not able to find any good resource for Ford-Fulkerson and Edmond Karp Algorithm for Max Network flow, Could you please do it in this series, I request you to add that as early as possible for you. Doubt in that algorithm - negative edge doesn't makes complete sense to me. I have Google interview in coming days, hope you will help me with it. ~Cheers to the work you guys are doing for the community
Hey, I have seen your comment in each and every video starting from the very beginning. Which year are you studying in? You must be very good at coding cuz someone who has been following this channel from.the beginning is bound to be a good coder😁
@@shang_chi4651 currently 2nd year Also , trust me , I’m not good at coding , I still fail many times when I solve new problems , probably more than 50% of the time But sometimes I can solve new problems only because I have done a similar problem in the past ,which is kinda cool
We can do this without sorting, first make a set of connection for type3 and calculate extra edges and then again calculate extra edges for alice and bob for type 1 and type 2 edges, keep track of number. of connected components of both the set, if any Ca or Cb != n then -1 else aliceEdge+bobEdge+redundantType3edge
Hi Subhesh, small optimization can be done in the code, it might degrade the readability but time complexity can be better, the optimization is: Rather than using Arrays.sort -> which in nlogn, simply have one for loop which will take into consideration only edge of Type 3 and mark them as visited then have the for loop again for other 2 types of edges. let me know if there is any fault or disadvantage of this approach.
No fault in approach. Visited array is not even needed. Just in the first iteration run only if type is 3. In the second iteration run for types 1 and 2.
You don't have to run the loop thrice. You can use a hashmap with Types as key. And run over the keys of hashmap. The space complexity might blow up but it will be done in single loop.
@@KejriwalBhakt Nice Thought, But I haven't suggested running the loop thrice, it is 2 times. That will be the case in your approach as well, moreover, it will take extra space as well, Here goes my explanation: 1> You will run through each edge to put it in your hashmap, so one loop is done. 2> For each type when you fetch the edges, on the values you will have to run a for loop, cumulative of which will be again O(n) we can say another set of traversal of all the edges. so, there is no extra benefit of Time complexity in this approach, and it is deteriorating the space complexity as well, let me know if you do not agree to it.