Maximum Number of K Divisible Components | Leetcode 2872

Поділитися
Вставка
  • Опубліковано 24 гру 2024

КОМЕНТАРІ • 48

  • @utsavjha9236
    @utsavjha9236 2 дні тому +1

    You are a great teacher, one of the best i have seen.

    • @techdose4u
      @techdose4u  2 дні тому +1

      thanks for your appreciation

  • @kheersagarpatel3195
    @kheersagarpatel3195 День тому +1

    Yes sir, your teaching is just awesome, i have got new enthusiasm for the DSA and i hope i will surely reach my dream destination by following you..

    • @techdose4u
      @techdose4u  День тому +1

      If DSA is the path to your destination then I guarantee you will be posting your success story with me in future here :)

    • @kheersagarpatel3195
      @kheersagarpatel3195 День тому +1

      @techdose4u waiting for that day and working for that day from my heart sir .....
      I am also your linkedin connection i hope you recognised me....

    • @techdose4u
      @techdose4u  День тому +1

      definitely let me know if I can help you :)

  • @sailendrachettri8521
    @sailendrachettri8521 3 дні тому +4

    today i participated in biweekly LC contest and was able to solve 1 question :)

  • @baka_man2512
    @baka_man2512 4 дні тому +7

    Thanks sir for this consistency 🙏

    • @techdose4u
      @techdose4u  4 дні тому +1

      Consistency is the key 🔑:)

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo 3 дні тому

    Literally, your explaination is very good. You slolved the complex problem using the simple concept and standard in greedy approach.This make me eassyly to get the idea to solve this.Thank you, teacher!

  • @Princekumar-ty4qp
    @Princekumar-ty4qp 3 дні тому +1

    Consistency🔥

  • @kky7811
    @kky7811 3 дні тому +1

    Great Explanation .
    Thanks for ur Effort 😎😎.

  • @AmarjeetKumar-to9ub
    @AmarjeetKumar-to9ub 3 дні тому +1

    Ty sir :)

  • @chandanaarvapally
    @chandanaarvapally 3 дні тому +1

    @techdose sir, i am getting tle for the above code? what to do?

    • @kiran1379
      @kiran1379 3 дні тому

      Check if you are passing values by reference or not

    • @techdose4u
      @techdose4u  3 дні тому

      Please check your recursion break condition & reference pass as mentioned :)

  • @gireeswar18
    @gireeswar18 4 дні тому

    In java code we can use a static variable and init with 0 on every call, this avoids using an array to store count.

    • @techdose4u
      @techdose4u  4 дні тому

      same can be done in c++ using static :)

    • @gireeswar18
      @gireeswar18 4 дні тому

      @techdose4u yes sir 😊

  • @indianofficialclashers9148
    @indianofficialclashers9148 4 дні тому

    In the dfs function , where does the recursion end and start going back ?

    • @techdose4u
      @techdose4u  3 дні тому

      recursion starts with exploring all adjancent edges and ends when loop ends after exploration is done

  • @gireeswar18
    @gireeswar18 4 дні тому +1

    Thank you sir. How to think about the solution like you sir? I feel stuck on seeing this problem.

  • @Anikait-h3d
    @Anikait-h3d 3 дні тому

    can you also start solving leetcode contest questions. It would really help all of us

  • @crazygamerrohan9899
    @crazygamerrohan9899 4 дні тому

    if i am passing the adj vector by valyue then it is showing me time limit exceed why??

    • @techdose4u
      @techdose4u  4 дні тому +1

      I had mentioned in the video about integer overflow.
      The return type of dfs needs to be set to 64-bit integer. Ex. Long Long dfs()

    • @ASHUTOSHSHARMA-us6hd
      @ASHUTOSHSHARMA-us6hd 4 дні тому

      @@techdose4u fir bhi tle aa rha hai, sir ji

    • @ASHUTOSHSHARMA-us6hd
      @ASHUTOSHSHARMA-us6hd 3 дні тому

      @@techdose4u class Solution {
      public:
      long long dfs(long long node, vector adj, vector& vals, int k,
      long long & counter, long long parent) {
      long long sum = vals[node];
      for (auto negh : adj[node]) {
      if (negh != parent) {
      sum += dfs(negh, adj, vals, k, counter, node);
      }
      }
      sum%=k;
      if(sum==0) counter++;
      return sum;
      }
      int maxKDivisibleComponents(int n, vector& edges,
      vector& vals, int k) {
      long long counter = 0;
      vector adj(n);
      for (auto it : edges) {
      int firstNode = it[0];
      int SecondNode = it[1];
      adj[firstNode].push_back(SecondNode);
      adj[SecondNode].push_back(firstNode);
      }
      dfs(0, adj, vals, k, counter, -1);
      return counter;
      }
      };

    • @ASHUTOSHSHARMA-us6hd
      @ASHUTOSHSHARMA-us6hd 3 дні тому

      @@techdose4u this code is giving tle, what to do??

    • @crazygamerrohan9899
      @crazygamerrohan9899 3 дні тому

      @@techdose4u means if iam passing vector as values then it requires stack space but in case of passing by reference it does not require stack space??

  • @indianofficialclashers9148
    @indianofficialclashers9148 4 дні тому +1

    Sir please explain the illustration you draw and the code side by side
    because many times what happens is beginners like me can't associate the two
    So it would be really helpful if you tell us which line of code corresponds to which illustration 🙂

    • @techdose4u
      @techdose4u  3 дні тому

      Many people might find it too boring hence avoiding that to manage within limited time :)

  • @Anikait-h3d
    @Anikait-h3d 4 дні тому

    ab lagta hai agle week tak trees and bfs ke upar hi question ayga

  • @AmitDaily_Vlogs
    @AmitDaily_Vlogs 3 дні тому

    sir aap robot ho kya explanation tora expressive bana skte ho kya

    • @techdose4u
      @techdose4u  3 дні тому +2

      If I make expressive then my sound quality will reduce.
      Good mic is costly hence just managing for my resources at hand :)

    • @AmitDaily_Vlogs
      @AmitDaily_Vlogs 3 дні тому

      @techdose4u okay sir you are doing great work and it was just a feedback 😁😁

    • @techdose4u
      @techdose4u  3 дні тому

      Yea I too realised that but waiting for collecting some amount for it then will change mic:)