Evaluate Division | With INTUITION | META, AMAZON | Leetcode-399 | Live Code 🧑🏻‍💻👩🏻‍💻

Sdílet
Vložit
  • čas přidán 19. 05. 2023
  • This is the 27th Video on our Graphs Playlist.
    In this video we will try to solve a very interesting Graph Problem "Evaluate Division" (Leetcode - 399)
    I am promising you, this problem will become easy once you are done with this video.
    If you have been following my "Graph Concepts & Qns" playlist , then these Qns will become very easy. Find the Link for that below.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Problem Name : Evaluate Division
    Company Tags : META, AMAZON
    My solutions on Github : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/evaluat...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
    #interviewpreparation #interview_ds_algo #hinglish

Komentáře • 71

  • @tauquirahmed1879
    @tauquirahmed1879 Před rokem +26

    Leetcode should publish this video in their official solution. ❤

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +11

      You made my day Tauquir ❤️❤️❤️
      It feels so good reading such comments
      Thank you from the bottom of my heart

  • @wearevacationuncoverers
    @wearevacationuncoverers Před rokem +7

    I think this is the speciality of this channel. He makes even a tough Qn look damn so easy. It literally becomes a piece of cake.

  • @souravjoshi2293
    @souravjoshi2293 Před rokem +3

    Beautiful solution to an insane Problem

  • @hirenjoshi6073
    @hirenjoshi6073 Před rokem +6

    Always Great 😊

  • @meshvpatel6112
    @meshvpatel6112 Před 4 měsíci +1

    Thanks a lot bhaiya ❤❤

  • @akshanshsharma6025
    @akshanshsharma6025 Před 7 měsíci +1

    I have no words to praise you

  • @ruchirshrikhande5584
    @ruchirshrikhande5584 Před 5 měsíci +1

    Bhai your explanations are amazing. You cover everything from how to even think about the problem and go all the way to implementing it. Thanks and please try to cover as many leetcode problems as you can so it will help fellow aspiring developers like us to build up the thought process of solving interview questions.Thanks for your videos and hope your channel grows even more. All the best !

  • @nishantdehariya5769
    @nishantdehariya5769 Před 4 měsíci +3

    salute to this explanation🖖

  • @wooldan7007
    @wooldan7007 Před rokem +3

    It was day before I was in search of this and here you are with very easy explanation. It would be really helpfull if you could also start discussing leetcode contests questions every sunday bcoz of you Iam trying every day questions thinking of back like you. thank you very much

    • @codestorywithMIK
      @codestorywithMIK  Před rokem

      So glad it is helping you.
      Thank you so much.
      And i will try soon to make contests solutions too.

  • @monty6393
    @monty6393 Před rokem +1

    Woooh.. When I saw this problem first time in mock interview series , I was scratching my head for 10-15 mins.. I wss getting some Vibes of graph but wasn't sure how exactly I will approach further specially the 1/ value part.. thanks for your Great explanation...
    One thing I would like to add on this that you are passing prod*val in the DFS function call there's a reason for that. Just in case anyone is wondering whyy.. because we want to multiply exact from src to destination paths not the useless path which comes on the way to DFS call..

  • @gp7060
    @gp7060 Před 3 měsíci

    Commenting on every video I watch. There is more recognition that you deserve ❤

  • @jatinkumar4410
    @jatinkumar4410 Před 3 měsíci +1

    Really helpful. Thanks for the video

  • @arjunsolanki2612
    @arjunsolanki2612 Před rokem +4

    What an explanation, Great Intuition building. Every video gives the same adrenaline rush. Looking forward to learn a lot from you Bhaiya❤.

  • @debashishbhattacharjee8188
    @debashishbhattacharjee8188 Před 6 měsíci +1

    Fantastic explanation.

  • @anuppatankar4294
    @anuppatankar4294 Před rokem +2

    As always best explanation 👌🏻

  • @prachuryapransarma
    @prachuryapransarma Před rokem

    Great Explanation

  • @Nabhivarsha
    @Nabhivarsha Před 4 měsíci +2

    dude u r awesome 🔥🔥🔥

  • @worldcricket3030
    @worldcricket3030 Před 10 měsíci

    Make a playlist on recursion How solve recursion problem

  • @sidharthdhiman4522
    @sidharthdhiman4522 Před rokem +1

    coolest solution ever sir , amazin

  • @codeandtalk6
    @codeandtalk6 Před rokem +1

  • @ManojKrVerma-vw4dx
    @ManojKrVerma-vw4dx Před rokem

    awesome explanation as always...

  • @ritikgupta.
    @ritikgupta. Před rokem

    Waiting for DSU approach.

  • @nishkarshsrivastava4576
    @nishkarshsrivastava4576 Před rokem +1

    Bro please if you can make greedy videos it would be really helpful.

    • @codestorywithMIK
      @codestorywithMIK  Před rokem

      Hi there
      I already have a Greedy playlist you can find in my channel.
      I will post more videos on that playlist

  • @xiaoshen194
    @xiaoshen194 Před rokem +4

    Yaar ye kis angle se graph ka ques Tha!! Its impossible to figure it out

  • @DhruvSharma-mh5vf
    @DhruvSharma-mh5vf Před rokem

    I was wondering if we can do some memoization using dp as well in this question???

  • @JJ-tp2dd
    @JJ-tp2dd Před rokem +1

    Thank you bhai..Today again I knew why C++ is better for DSA than Java. Java Implementation:
    class Pair {
    String first;
    double second;

    Pair(String _first, double _second) {
    this.first = _first;
    this.second = _second;
    }
    }
    class Solution {

    private double ans = -1.0;

    private void DFS(String src, String des, Set visited, Map adj, double product) {

    if(visited.contains(src)) {
    return;
    }

    visited.add(src);

    if(src.equals(des)) {
    ans = product;
    return;
    }

    for(Pair pair : adj.get(src)) {
    String v = pair.first;
    double val = pair.second;

    DFS(v,des,visited,adj,product*val);
    }
    }

    public double[] calcEquation(List equations, double[] values, List queries) {
    int n = equations.size();
    Map adj = new HashMap();

    //Make the graph
    for(int i=0; inew ArrayList()).add(new Pair(v, value));
    adj.computeIfAbsent(v, k->new ArrayList()).add(new Pair(u, 1.0/value));
    }

    int N = queries.size();
    double[] result = new double[N];

    int pos = 0;

    for(int i=0 ; i

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      Thanks JJ ❤️❤️

    • @surajsidar3280
      @surajsidar3280 Před měsícem

      Thanks for the Java code.
      Yes C++ is better for DSA than Java but what if the interviewer wants you to code in Java since you have applied for the Java Developer role
      I was checking src==dest instead src.equals(des)
      This is a common mistake when you compare strings in Java
      In Java, when you pass a primitive type (like double) to a method, it is passed by value
      So your code helped me to declare ans variable as a global variable

  • @tarawantimukhija4713
    @tarawantimukhija4713 Před rokem +1

    why this man is so underrated. ???????

    • @tarawantimukhija4713
      @tarawantimukhija4713 Před rokem +1

      I can't wait to see what mind-blowing content you come up with next!

    • @codestorywithMIK
      @codestorywithMIK  Před rokem

      It means a lot to me Jay ❤️❤️❤️

    • @souravjoshi2293
      @souravjoshi2293 Před rokem +1

      That's what I keep thinking. What I have noticed is that this guy never asks us to like or subscribe to his channel like other CZcamsrs do in general.
      I don't know the reason why.

  • @kartikkk4583
    @kartikkk4583 Před rokem +2

    Saw the question kind of got the logic after seeing the hints but then thought it cant be that complex, came to video saw till 7 minutes and went to LC and coded it , wasn't that hard, sometimes mind scares you when you trying to do something new or new way of implementations . CODE :
    class Solution {
    public:
    vector calcEquation(vector& equations, vector& values, vector& queries) {
    vector ans;
    unordered_map m;
    for(int i=0;i

  • @JJ-tp2dd
    @JJ-tp2dd Před rokem

    Bhai could you please name the topics that are left and jo ap graph concepts series me cover karenge? I think Floyd Warshall and articulation points h..aur v hain kya? now that DP series v start ho rhi.. Also as a suggestion, DP series ki introduction me batana dp me kya kya cover krenge like knapsack, dp with bit masking etc so that aur reach aaye ♥💙

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +3

      Hi JJ,
      Sure i will include the Roadmap and topics for DP in my first video.
      And for Graphs,
      We are also left with MST (minimum spanning tree) along with what you have mentioned.
      But not much is left now. I think within next 2 weeks we should be done with all important ones.
      Only thing left will be the Qns from then onwards.

    • @JJ-tp2dd
      @JJ-tp2dd Před rokem +1

      @@codestorywithMIK thank youu ❤😻

  • @udaykumarchetla6205
    @udaykumarchetla6205 Před rokem +2

    DSU approach??

  • @rajkrishanmahajan2373
    @rajkrishanmahajan2373 Před rokem +2

    i am waiting for DP PlayList 😊😊

  • @udaykumarchetla6205
    @udaykumarchetla6205 Před rokem +1

    As u said relation type questions he tho graph hi he..iske pehle equations ka ek question dekha apka... tho laga ki ye question graph hi he

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      Exactly Uday.
      I am glad you were able to identify that ❤️❤️

    • @udaykumarchetla6205
      @udaykumarchetla6205 Před rokem +1

      Bro DSU union by rank aur size dono ka video banao na?

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      By Rank is already there - czcams.com/video/iH3XVIVzl7M/video.html
      By size, i will create soon.

    • @udaykumarchetla6205
      @udaykumarchetla6205 Před rokem +1

      @@codestorywithMIK I already watched your video on rank. Waiting from so long for the other one....

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      Sure. Will try to cover that soon.
      Currently a little occupied to start DP concepts playlist ❤️❤️

  • @AnkitSingh-tm5dp
    @AnkitSingh-tm5dp Před rokem

    Atmost able to solve but I doubt in dfs for(auto &v : adj[source]){
    //Why not check
    if(set.find(v)!=set.end()){
    //Then dfs
    }
    Like in dfs we check the node is already visited or not Sir, why we cannot check visited in for loop of adj 🤔
    }

    • @codestorywithMIK
      @codestorywithMIK  Před rokem

      I think you can do that too. Can you please try and share

    • @AnkitSingh-tm5dp
      @AnkitSingh-tm5dp Před rokem

      @@codestorywithMIK Yes is work's thanku for clearing the doubt:
      //This is the code It's works perfectly
      class Solution {
      public:

      void dfs(unordered_map &adj,string N,string D,double &cost,unordered_set &st,double product){
      if(st.find(N)!=st.end()) return;

      st.insert(N);
      if(N==D){
      cost = product;
      return;
      }


      for(auto &v : adj[N]){
      if(st.find(N)!=st.end()){ //check for visited:
      string f = v.first;
      double s = v.second;
      dfs(adj,f,D,cost,st,product*s);
      }
      }
      }
      vector calcEquation(vector& equations, vector& values, vector& queries) {
      unordered_map adj;
      for(int i=0;i

    • @codestorywithMIK
      @codestorywithMIK  Před rokem +1

      Thanks for sharing your code ❤️❤️❤️💪💪

  • @MAMILLAPALLISUMANTHBCE
    @MAMILLAPALLISUMANTHBCE Před 3 měsíci

    it will be more helpful if you teach it in English because every one don't know English right ,hope you understand

  • @floatingpoint7629
    @floatingpoint7629 Před rokem

    BFS solution:
    /**
    * @param {string[][]} equations
    * @param {number[]} values
    * @param {string[][]} queries
    * @return {number[]}
    */
    var calcEquation = function (equations, values, queries) {
    const adj = new Map();
    for (let i = 0; i < equations.length; i++) {
    const [u, v] = equations[i];
    const value = values[i];
    if (!adj.has(u)) adj.set(u, []);
    adj.get(u).push([v, value]);
    if (!adj.has(v)) adj.set(v, []);
    adj.get(v).push([u, 1 / value]);
    }
    const dfs = (src, dst) => {
    if (!adj.has(src) || !adj.has(dst)) return -1;
    const [q, visited] = [[], new Set()];
    q.push([src, 1]);
    visited.add(src);
    while (q.length) {
    const [node, weight] = q.shift();
    if (node == dst) return weight;
    for (const [nei, neiWeight] of adj.get(node)) {
    if (!visited.has(nei)) {
    q.push([nei, neiWeight * weight]);
    visited.add(nei);
    }
    }
    }
    return -1;
    }
    return queries.map(([src, dst]) => dfs(src, dst));
    };