Paths from root with a specified sum | Simple | Story To Code | GfG POTD

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

ความคิดเห็น • 24

  • @GauravDuseja-t6q
    @GauravDuseja-t6q 9 หลายเดือนก่อน +1

    Bhaiya why not doing currSum-=temp.pop_back() may you please explain🙏

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +7

      I believe you are asking why we are not doing
      curr_sum = curr_sum - temp.back()
      The reason is, we are not passing curr_sum as reference, so when the recursion rolls back, the curr_sum will come back to it last value at that recursion point.
      Notice that we are passing temp by reference, so any change to it will be reflected to every recursive point and hence we need to undo it before rolling back to last recursion point.
      Why we are passing temp by reference (&) ?
      Because, passing it by copy will increase time complexity because every time i pass a parameter, a copy will be made if I don’t pass it by reference.
      Hope this helps

    • @lostcyrus8578
      @lostcyrus8578 9 หลายเดือนก่อน

      @@codestorywithMIK I was also confused in this. Thanks for answering

    • @GauravDuseja-t6q
      @GauravDuseja-t6q 9 หลายเดือนก่อน

      @@codestorywithMIK thanku bhaiya 🙏

  • @gui-codes
    @gui-codes 5 หลายเดือนก่อน

    I think you are the creator of "story to code" concept. Never seen this unique style before

  • @wearevacationuncoverers
    @wearevacationuncoverers 9 หลายเดือนก่อน +3

    I am able to do these problems now because of you. Thank you from the bottom of my heart. From me and my entire friend circle.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 9 หลายเดือนก่อน

    Good explanation understood i have solved this same intuition thanks jai shree ram.

  • @gauravbanerjee2898
    @gauravbanerjee2898 9 หลายเดือนก่อน

    Thanks a lot bhaiya ❣🫡

  • @meetagarwal547
    @meetagarwal547 9 หลายเดือนก่อน +1

    Just a gentle advise bhai
    If you could arrange the playlist videos in order of difficulty it would boost your views.
    Also like Raj sir has uploaded videos in order jisme har particular topic (i.e graphs.dp,linked list) ke playlist ka agla video pichle video se related ho so it would definitely help you boost your channel exponentially.
    Btw nice video bhai keep it up♥️

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +2

      Hi there,
      Actually i follow this pattern in my Concepts Playlist.
      As of now I have 2 Concepts playlist
      1) DP Concepts & Qns
      2) Graph Concepts & Qns
      It’s in order. Every video is related to last video . Topic wise coverage. You can find their links in the Description
      I am currently working on concepts playlist of other topics too. Soon they are coming.
      Thank you so much for this precious suggestion and your kind words. ❤️❤️🙏🙏

  • @aneesh_sayal
    @aneesh_sayal 9 หลายเดือนก่อน

    MIK, would you be able to make a video for Leetcode 322, Coin Change. Also, Please update the DP concepts playlist. Love your solutions. Thanks

  • @bhartendupant8859
    @bhartendupant8859 9 หลายเดือนก่อน

  • @ishaansharma6553
    @ishaansharma6553 9 หลายเดือนก่อน

    thankyou bhaiya

  • @lostcyrus8578
    @lostcyrus8578 9 หลายเดือนก่อน +1

    I have one question if we check for sum==TotalSum before adding value in current sum then it is giving multiple values whyy???

    • @ayushsaini4356
      @ayushsaini4356 4 หลายเดือนก่อน

      did you got the answer??? i have the same question

  • @krishnan828
    @krishnan828 9 หลายเดือนก่อน

    Jai Shree Ram

  • @dhruvbandi6633
    @dhruvbandi6633 9 หลายเดือนก่อน

    Partition Array Into Two Arrays to Minimize Sum Difference | Leetcode #2035
    please make a video on this problem plzz

  • @pratyushraghuvanshi1543
    @pratyushraghuvanshi1543 9 หลายเดือนก่อน

    Leetcode 1477. Find Two Non-overlapping Sub-arrays Each With Target Sum plase can you explaination of this problem..please i request you post a video on this problem sir..

  • @ranjeetKumar-ik8sf
    @ranjeetKumar-ik8sf 9 หลายเดือนก่อน +2

    Hi, please upload the recursion concept and questions I have been waiting for the last two please this is my humble request because I tried many recursion playlists I am still confused about recursion.

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +3

      sure. Coming in few days.

    • @DevOpskagyaan
      @DevOpskagyaan 9 หลายเดือนก่อน +1

      Waiting eagerly sir

  • @jambajuice07
    @jambajuice07 9 หลายเดือนก่อน +2

    what if we had to find the paths from any node to any node with sum k

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +5

      In that case, you will have to use the same approach we would do in an array to find any subarray having sum = k.
      You can use map.
      Find the code below :
      class Solution {
      public:
      map mp;
      void pathNums(TreeNode* root, int currSum, int sum, int &count) {
      if(!root)
      return;
      currSum += root->val;
      if(mp.count(currSum-sum)) {
      count += mp[currSum-sum];
      }
      mp[currSum]++;
      pathNums(root->left, currSum, sum, count);
      pathNums(root->right, currSum, sum, count);
      mp[currSum]--;
      }
      int pathSum(TreeNode* root, int sum) {
      if(!root)
      return 0;
      mp.clear();
      mp[0] = 1;
      int count = 0, currSum = 0;
      pathNums(root, currSum, sum, count);
      return count;
      }
      };

    • @jambajuice07
      @jambajuice07 9 หลายเดือนก่อน

      @@codestorywithMIK got it thanks !