Dp 16. Partition A Set Into Two Subsets With Minimum Absolute Sum Difference | DP on Subsequences

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.พ. 2022
  • Lecture Notes/C++/Java Codes: takeuforward.org/dynamic-prog...
    Problem Link: bit.ly/3t62bqQ
    Pre-req for this Series: • Re 1. Introduction to ...
    a
    Make sure to join our telegram group for discussions: linktr.ee/takeUforward
    Full Playlist: • Striver's Dynamic Prog...
    In this video, we solve the problem of Partition a set into two subsets such that the difference of subset sums is minimum. This problem is the third problem on DP on Subsequences Pattern. Please watch DP 14 before watching this.
    If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
    You can also get in touch with me at my social handles: linktr.ee/takeUforward

ความคิดเห็น • 1K

  • @takeUforward
    @takeUforward  2 ปีที่แล้ว +176

    I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.
    Keeping a like target of 500 ❤✌🏼

    • @divyaporwal589
      @divyaporwal589 2 ปีที่แล้ว +9

      It is not working with negative numbers, for example the array is -36,36 and then the target is zero

    • @harshitrawat138
      @harshitrawat138 2 ปีที่แล้ว

      @@divyaporwal589 Dp requires array and array can't have negative indexes. If array contains negative numbers you can subtract the most negative number of given array (minx) from every element array so the all the elements will be positive.

    • @spytonic4171
      @spytonic4171 2 ปีที่แล้ว

      @@harshitrawat138 truee but the problems comes when there is a random so if we check for negetive numbers at starting and find diff with each number the we can return it other wise we can continue this algo nice idea

    • @kaushalwaghela429
      @kaushalwaghela429 2 ปีที่แล้ว +4

      understood
      if possible, please give leetcode and gfg problem links also.
      thanks :)

    • @trendtoyou7967
      @trendtoyou7967 2 ปีที่แล้ว

      We need not calculate minimum repeatedly. Traverse last row in dp array in reverse order and return first true cell.... Total-2*i

  • @aryashjain7893
    @aryashjain7893 ปีที่แล้ว +72

    understood, but the leetcode question mentioned in the sheet requires meet in the middle approach as it has got negative values, and tabulation fails in this case.

    • @ankitanand1539
      @ankitanand1539 8 หลายเดือนก่อน +1

      Use long long

    • @fettuccine794
      @fettuccine794 6 หลายเดือนก่อน

      Exactly !!!

    • @dhananjaygorain6375
      @dhananjaygorain6375 5 หลายเดือนก่อน +1

      @@ankitanand1539 still it showing runtime error can you give your code please

    • @gamersgame43
      @gamersgame43 3 หลายเดือนก่อน

      use unordered_set?

    • @ganishk3568
      @ganishk3568 15 วันที่ผ่านมา +1

      @aryadhjain7893 that is not an issue if you have initial offset of 10⁷. But the problem is requires both the partitions should be of equal size.

  • @vikasbagri1225
    @vikasbagri1225 ปีที่แล้ว +24

    Understood it very well
    Thanks for this amazing series
    You really are contributing a lot to this community
    Best DP series in the whole youtube

  • @sakshisakshi5677
    @sakshisakshi5677 2 ปีที่แล้ว +22

    You made the concept clear easily and smoothly🙌

  • @pratikdas1780
    @pratikdas1780 ปีที่แล้ว +5

    I could do the memoized version on my own, but could never do it the bottom-up way. today, i can say that it's clear. and it was damn simple. just checking the sums my array of size n can produce. amazing insight.

  • @nikhilprasad644
    @nikhilprasad644 2 ปีที่แล้ว +62

    bro this problem work only for +ve numbers and not on negative numbers. pls do make a follow up for negative numbers as well, as it might come up in an interview. good companies do ask such.
    thanks

    • @user-hz2nh8kg6x
      @user-hz2nh8kg6x 8 หลายเดือนก่อน +9

      Did you come across a solution for the negative numbers?

    • @EerieEntertainment-mc4ce
      @EerieEntertainment-mc4ce 6 หลายเดือนก่อน

      @@user-hz2nh8kg6x agar array ka minimum element negative hai to saare element me use add krke array ko non negative banalo

    • @manikiran949
      @manikiran949 5 หลายเดือนก่อน +8

      Hey did you find a dp solution for negative numbers ? , I have seen in leetcode that it is unsolvable with dp for negative numbers .Thanks

    • @ramakrishnan4356
      @ramakrishnan4356 4 หลายเดือนก่อน +2

      Instead of storing in array store the same in map create map where you can store corresponding sum for values this way we can handle negatives also

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

      @@ramakrishnan4356 thx mate

  • @SahanaaEvan-mo6zv
    @SahanaaEvan-mo6zv ปีที่แล้ว +7

    Understood! Striver you are just brilliant. Your explanation and these concepts are blowing my mind off! Damn I got lucky coz i found a teacher like you! Thank you so much!

  • @vikasgupta6701
    @vikasgupta6701 ปีที่แล้ว +77

    Able to solve this problem without seeing the video and using concepts learned in past two videos. That's the power of striver's lectures. Thanks!!

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

      exactly

    • @pritimurmu7898
      @pritimurmu7898 9 หลายเดือนก่อน +16

      bro how did you solve for negetives

    • @prashantpal3510
      @prashantpal3510 7 หลายเดือนก่อน

      me too

  • @sanginigupta1312
    @sanginigupta1312 2 ปีที่แล้ว +7

    Was able to solve this in a single go, thank you striver bhaiya, only because of these videos I'm able to develop an intuition in DP problems

  • @VY-zt3ph
    @VY-zt3ph 2 ปีที่แล้ว +6

    This is the question which I was eagerly waiting for you to upload since the day you uploaded first DP lecture in this playlist.

  • @JeevanGaikwad-G1
    @JeevanGaikwad-G1 2 ปีที่แล้ว +2

    Understood. Very nicely explained the tough problem in an elegant way. Thanks.

  • @udaypratapsingh8923
    @udaypratapsingh8923 ปีที่แล้ว +5

    you made the concept clear easily and smoothly🙌 : )

  • @channelname4394
    @channelname4394 2 ปีที่แล้ว +8

    Best explanation. understood , hope this channel reaches more people

  • @visheshagrawal8676
    @visheshagrawal8676 ปีที่แล้ว +6

    it took me 50 mins to solve the question without looking the answer it's all because of you the way you teach.. ✨✨✨✨

  • @shreyashtech8556
    @shreyashtech8556 3 หลายเดือนก่อน

    Dude, really thankful to you man. I solved this question and 95% of the previous questions on my own. the reason is you. your explanation is out of the world. thanx again. hope we meet in person in the near future.

  • @dharmeshpoladiya9047
    @dharmeshpoladiya9047 2 ปีที่แล้ว +1

    Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥

  • @user-ie8sy7wo4m
    @user-ie8sy7wo4m ปีที่แล้ว +31

    Quick Tip 💡: If you want to solve this using memoization, you need to make sure that you call the recursive function for all possible targets. For example let the sum = 10, so target = 5. Now if you call function for 5 i.e. F(n,5) it may not always fill the complete dp grid. So you have to call all F(n,5) F(n,4) .... F(n,0) to make sure all dp[i][j] are filled.
    This won't affect the time complexity as if it was previously calculated it won't be calculated again due to memoization.
    In tabulation we go from 0 -> n, filling all dp[i][j] no matter what, so in that case it all indexes are filled.

    • @kishorkumarbehera5412
      @kishorkumarbehera5412 11 หลายเดือนก่อน

      Can you give me the code for reference ?

    • @user-ie8sy7wo4m
      @user-ie8sy7wo4m 11 หลายเดือนก่อน

      public class Solution {
      public static int minSubsetSumDifference(int[] arr, int n) {
      int sum = 0;
      for(int num : arr)
      sum += num;
      int k = sum/2;
      if(n==1)
      return arr[0];
      if(k==0)
      return 0;
      Boolean[][] dp = new Boolean[n][k+1];
      for(int i=k; i>=0; i--)
      find(arr, i, n-1, dp);
      for(int i=k; i>=0; i--){
      if(dp[n-1][i]!=null && dp[n-1][i])
      return sum - (2*i);
      }
      return -1;
      }
      private static boolean find(int[] arr, int k, int i, Boolean[][] dp){
      if(k==0)
      return true;
      if(i

    • @user-ie8sy7wo4m
      @user-ie8sy7wo4m 11 หลายเดือนก่อน

      @@kishorkumarbehera5412 added the code

    • @kishorkumarbehera5412
      @kishorkumarbehera5412 11 หลายเดือนก่อน

      @@user-ie8sy7wo4m Instead of calling for each target we can call it for sum/2. So when we are picking and not picking we have the sum of the subset, so we can store the difference between the subset sum and the target which is total sum/2, and taking minimum of all subsets. So when returning the final answer we should check if the total sum is even or odd. Accordingly the answer would be 2*ans or 2*ans+1.

    • @RohitKumar-jd7un
      @RohitKumar-jd7un 10 หลายเดือนก่อน

      code for this approach
      bool helper(int ind,int k,vector &arr,vector &dp)
      {
      if(k==0)
      {
      return true;
      }
      if(ind==0)
      {
      if(arr[ind]==k)
      {
      return true;
      }
      else
      return false;
      }
      if(dp[ind][k]!=-1)
      {
      return dp[ind][k];
      }
      bool nottake=helper(ind-1,k,arr,dp);
      bool take=false;
      if(arr[ind]

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

    We can optimize space complexity here since maximum value a subset can take for minimum absolute difference is total_sum/2 so we can make 2d vector for total_sum/2 instead of total_sum and then iterate last row of vector from last col and the first cell with true will be subset1.

  • @cyro_-ej6xm
    @cyro_-ej6xm หลายเดือนก่อน

    kudos striver, you are the reason i got my confidence back , thanku so much , appreciate all the hard work you do , it changes life of thousands .

  • @mrsunny8299
    @mrsunny8299 ปีที่แล้ว +2

    understood, i dont know why i was skipping dp,
    it is easy, (you made it easy to understand this).
    Thankyou.

  • @paridhijain7062
    @paridhijain7062 2 ปีที่แล้ว +9

    Understood. Sir, You are really making great efforts for students like us. Thank you for teaching us.

  • @alessandrocamilleri1239
    @alessandrocamilleri1239 ปีที่แล้ว +4

    Great video. I simplified the minimum subset difference as follows:
    int i = totSum / 2;
    while (!dp[i]) i- -; // will not go out of bounds since i always stops at dp[0] which is always true
    return (totSum - i) - i;

  • @surya4193
    @surya4193 ปีที่แล้ว

    thanks striver,I am able to improve my coding skills the main reason is you and your way of teaching

  • @codelikebeast3971
    @codelikebeast3971 ปีที่แล้ว +1

    Awesome Striver , I was confused in how dp vector is formed step by step and what does it signifies, you cleared it with so much clearity . Respect

    • @iamnoob7593
      @iamnoob7593 6 หลายเดือนก่อน

      same i had doubt too abt it now its clear.

  • @anshul5533
    @anshul5533 2 ปีที่แล้ว +33

    Striver bhaiya i think it can be further optimized in terms of time and space if we take our sum as sum/2 initially (as we have taken in DP-15), then the TC : N * (k/2) and SC : (k/2) because we are just bothered about S1 till k/2

    • @takeUforward
      @takeUforward  2 ปีที่แล้ว +36

      True.. concept clear hone se u urself can do these small things :P

    • @sparks8754
      @sparks8754 2 ปีที่แล้ว +1

      Inspiring

    • @deepaksarvepalli2344
      @deepaksarvepalli2344 2 ปีที่แล้ว +10

      I am searching for this comment... satisfied...😂

    • @vanshsehgal9475
      @vanshsehgal9475 2 ปีที่แล้ว +1

      Can you explain a lit bit more? I did not clearly get what are you trying to say..

    • @abhishekcs5468
      @abhishekcs5468 ปีที่แล้ว

      @@vanshsehgal9475
      You basically try to find target as upperbound of sum/2 and optimize for closest. Here is the memoized solution without space optimization.
      ---------------------------------------------------------------------------------------------------------------------------
      int dfs(int ind, int upperBound, vector& nums, vector& dp){
      if(ind > nums.size() - 1) return 0;

      if(dp[ind][upperBound] != -1) return dp[ind][upperBound];

      int notTaken = dfs(ind + 1, upperBound, nums, dp);
      int taken = -1e8;
      if(nums[ind]

  • @hemasaijammana5658
    @hemasaijammana5658 2 ปีที่แล้ว +15

    This is the same question I was asked in yesterday's interview. I came with recursive and then tried of memoization.
    After memoization it is giving me TLE, now I am watching this video

  • @himanshujindal1532
    @himanshujindal1532 2 ปีที่แล้ว +2

    I appreciate the hardwork you putting

  • @ishaanchandak4774
    @ishaanchandak4774 11 หลายเดือนก่อน +1

    i found this one a bit harder than the previous ones but gave time watching video and doing it by myself and understood it . great work man . n

  • @dennyage4791
    @dennyage4791 2 ปีที่แล้ว +12

    What if we have negative integers in an array, then this approach won't work ??

  • @meerapanchal8258
    @meerapanchal8258 27 วันที่ผ่านมา +2

    For those who are having 49/50 testcase passing on coding ninjas iterate the inner loop upto target/2 and while calculating minimum absolute difference, iterate loop from target/2 to 0 and as soon as you get first true value break the loop (maximum the target value when dp[n-1][target] is true , minimum the absolute difference)

  • @kotipallimadhumeher71
    @kotipallimadhumeher71 2 ปีที่แล้ว +2

    Understood bhaiya!! In short we can say that the dp table last row defines whether the target value is possible from given array or not.Then all possible target values are derived from the dp table and we can take min diff among the all abs diff.

  • @user-rs9io6yf9k
    @user-rs9io6yf9k ปีที่แล้ว +8

    Bhayya can you explain how can we handle the negetive cases where -10^7

  • @aryanbhagat6252
    @aryanbhagat6252 2 ปีที่แล้ว +11

    How do we do this with negative elements as well?

  • @cinime
    @cinime 2 ปีที่แล้ว +1

    Understood! Thank you so much for the amazing explanation!!!

  • @piyushsaxena6243
    @piyushsaxena6243 2 ปีที่แล้ว +2

    understood, thanks for these amazing lectures bhaiya ❤️

  • @amritanshusinha9401
    @amritanshusinha9401 ปีที่แล้ว +4

    Hey bro!
    Great video and explanation!
    Just had a small question. How would you approach a similar problem where the sizes of both the partitioned subsets must be equal?

  • @pritikasharma9857
    @pritikasharma9857 ปีที่แล้ว +14

    Amazingly explained!. But I had a doubt won't this method fail if we have negative elements in the given array ? Could you explain this too

    • @amritanand1714
      @amritanand1714 11 หลายเดือนก่อน +1

      Yeah it's a problem. I think we cannot solve then through this way. There are questions on leetcode with negative values. Anyone please reply if they have any solution for this?

  • @rishabhgupta9846
    @rishabhgupta9846 ปีที่แล้ว

    understood,able to solve by my own .What I was doing is calling memoization for every subset sum s1 which is giving me TLE. But using tabulation we don't need to call memoization again and again and can solve in one go

  • @madhurgupta4220
    @madhurgupta4220 ปีที่แล้ว

    Very Good Explanation. Understood. I think this will be more than enough

  • @bapanmandal9019
    @bapanmandal9019 ปีที่แล้ว +22

    In case of negative integers, what should we can do ,vaiya ?

    • @HarshKumar-ip5nr
      @HarshKumar-ip5nr 11 หลายเดือนก่อน +2

      substract min(nums.begin(), nums.end()) from each element.

  • @shivamdwivedi8120
    @shivamdwivedi8120 ปีที่แล้ว +30

    In case of negative integers, what should we can do ?

    • @VishalGupta-jh9nz
      @VishalGupta-jh9nz ปีที่แล้ว +2

      Just add absolute value of minimum integer to every element

    • @avicr4727
      @avicr4727 ปีที่แล้ว

      @@VishalGupta-jh9nz can you provide me the code it will be very helpful

    • @VishalGupta-jh9nz
      @VishalGupta-jh9nz ปีที่แล้ว +2

      @@avicr4727 Yes, I can provide but it gives TLE
      class Solution {
      public:
      int f(int ind, int target, int sum, int size,vector& nums, int n,vector&dp ){
      if(ind==-1 && size==n/2){
      return abs(target-2*sum);
      }
      if(ind==-1 || size>n/2){
      return 1e8;
      }
      if(dp[sum][size]!=-1)return dp[sum][size];
      int notTake = f(ind-1,target,sum,size,nums,n,dp);
      int take = f(ind-1,target,sum+nums[ind],size+1,nums,n,dp);
      return dp[sum][size] = min(take,notTake);
      }
      int minimumDifference(vector& nums) {
      int n = nums.size();
      int mini = 0;
      for(int i=0;i

    • @yogeshlamba5485
      @yogeshlamba5485 ปีที่แล้ว +1

      @@VishalGupta-jh9nz Consider an array , arr = [-1e7, 4, 7, 1e8, 6]
      The minimum number here is -1e7, and if go for adding this to all elements, adding it to 1e8 will be out of INT_MAX.

    • @keshavbaheti7327
      @keshavbaheti7327 ปีที่แล้ว +1

      ​@@yogeshlamba5485 use long long and guess what 1e7 +1e8 is not equal to 1e9.😊

  • @imranimmu4714
    @imranimmu4714 ปีที่แล้ว

    Raj bhaiyya, no one could have taught this better than you,
    Thank you soo much

  • @zeppelinpage861
    @zeppelinpage861 ปีที่แล้ว +1

    Absolutely brilliant!!! Thanks a lot

  • @krishan_aggarwal9376
    @krishan_aggarwal9376 2 ปีที่แล้ว +26

    Please make a video regarding neagtive values too 😓. This one understood❤❤

  • @shantanu240895
    @shantanu240895 2 ปีที่แล้ว +56

    How would you handle this problem in case the numbers in an array are negative or zero too? The tabulation wouldn't work in such a scenario.

    • @sherlockholmes1605
      @sherlockholmes1605 2 ปีที่แล้ว +2

      It would right? if we add an extra check to see if the index is going out of bounds for dp[i-1]th row.

    • @ihsannuruliman3656
      @ihsannuruliman3656 2 ปีที่แล้ว +1

      it would work yeah just check of out of bounds.

    • @SR-we1vl
      @SR-we1vl 2 ปีที่แล้ว

      Can you please share the code!

    • @tusharnain6652
      @tusharnain6652 2 ปีที่แล้ว +17

      It wont work with negatives, there's a negative number case in leetcode, this solution fails there.

    • @jigardoshi2852
      @jigardoshi2852 2 ปีที่แล้ว +1

      Yes agreed, this DP solution will not work when numbers are negative or 0 or for matter if totalSum of all nums is 0.

  • @sahilbadkul7130
    @sahilbadkul7130 2 ปีที่แล้ว

    Understood man, grt explanation make every hard concept as easy as you can.
    then there is not something like difficult.
    😇

  • @vinaykumarratnala5832
    @vinaykumarratnala5832 ปีที่แล้ว

    I have solved this question before watching this video only based on the concepts applied in all prev videos. thank you so much

  • @prajjwalpandey2278
    @prajjwalpandey2278 2 ปีที่แล้ว +11

    This can be alternatively solved, if we can find a subsequence with sum closest to
    totalSum/2.
    Correct me if I'm wrong.

    • @vedanshbhardwaj6548
      @vedanshbhardwaj6548 ปีที่แล้ว

      ya even I did so, but somehow the space optimised solution went wrong

    • @amitmahato6404
      @amitmahato6404 ปีที่แล้ว

      [2,3,7], sum/2=6, closest sum can be 5 or 7

    • @vedanshbhardwaj6548
      @vedanshbhardwaj6548 ปีที่แล้ว

      @@amitmahato6404 ya but the catch is we will only check till totalSum/2....because if one is say 5, other is bound to be 7 so why check for anything greater than the totalSum/2

    • @amitmahato6404
      @amitmahato6404 ปีที่แล้ว

      @@vedanshbhardwaj6548 yeh, S1=5, SO S2 WILL BE 7, MIN DIFF IS 2

  • @guptashashwat
    @guptashashwat ปีที่แล้ว +8

    If array elements are negative what should we do?

    • @denishfuletra7863
      @denishfuletra7863 ปีที่แล้ว

      let me know if you find ans for negative elements.

  • @MukeshKumar-cc3uh
    @MukeshKumar-cc3uh 4 หลายเดือนก่อน

    Understood ❤ and thanks for the inspiration by working at 4AM in the morning.

  • @mohankrishna4375
    @mohankrishna4375 13 วันที่ผ่านมา

    Amazing! thankyou DSA parasurama striver
    best teacher ever in my life.

  • @parasjaggi268
    @parasjaggi268 2 ปีที่แล้ว +7

    understood i tried earlier i made recursion but wasn't able to make it to dp ,,,,,,,,,thanks for making it easy

  • @Pavankumar-ck5ot
    @Pavankumar-ck5ot 2 ปีที่แล้ว +5

    Understood.
    I think if we declare dp array of size [n][total sum/2+1] will also work.

  • @rajsekhardutta8891
    @rajsekhardutta8891 2 ปีที่แล้ว +1

    Amaazing explanation! Understood!🤩❤

  • @arpnasjs9825
    @arpnasjs9825 ปีที่แล้ว

    Understood
    Thanks for this amazing series

  • @sannareddymonesh7598
    @sannareddymonesh7598 ปีที่แล้ว +8

    This problem is entirely depending upon the total sum of array . What if the total sum of array is negative. Then we cannot create negative size dp array

    • @balakrishnanr648
      @balakrishnanr648 ปีที่แล้ว +2

      in LC its that way

    • @softwarefoodiee
      @softwarefoodiee ปีที่แล้ว

      Sum cannot be negative sunce its mentioned that all the elements are non-negative.

  • @prateeksharma3698
    @prateeksharma3698 2 ปีที่แล้ว +3

    If negative elements are also present in given array then what will be maxSum ?

  • @abhishekjhanji3014
    @abhishekjhanji3014 2 ปีที่แล้ว +14

    "Understood" ....Guess what I coded this problem with a different approach and my score is 100 in this problem of """DP""" ....It's amazing to solve DP ..Thanks bhaiya ....
    My code here using memoization..
    int findans(int a,int t_sum,vector&arr,int i,int &min_v,vector&dp){
    if(i

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

    Explained beautifully ♥

  • @ranasauravsingh
    @ranasauravsingh 2 ปีที่แล้ว +1

    UNDERSTOOD... !
    Thanks striver for the video... :)

  • @nitishverma1484
    @nitishverma1484 ปีที่แล้ว +5

    Its a suggestion, If you could explain the need of the array as you explained it in this video , in DP-14 video , as I was very confused as to what those T/F represent till end. Now it gets cleared here. I have traced the whole array for that and also that arr[0]

  • @adi_7861
    @adi_7861 2 ปีที่แล้ว +6

    How we can make it work if array contains negative elements as well?

    • @anshumansharma2251
      @anshumansharma2251 2 ปีที่แล้ว +1

      meet in the middle or binary search

    • @aryanbharat9749
      @aryanbharat9749 2 ปีที่แล้ว

      @@anshumansharma2251 can you explain why not for negative numbers
      I mean cant we use Hash Map or something?

  • @paveshkanungo6338
    @paveshkanungo6338 8 หลายเดือนก่อน

    Understood! Thank you Striver

  • @tanvirarjel
    @tanvirarjel 2 ปีที่แล้ว

    In the first block of for loops, we don't need to check the target until the total sum. we can check target until totalSum / 2 if total sum even or totalSum/ 2 + 1 if totalSum is odd.

  • @ShubhamKumar-vp4pu
    @ShubhamKumar-vp4pu 2 ปีที่แล้ว +7

    Hey striver, I have understood the concept but can we solve it using recursion ?

    • @sjsjdsbsjjwjs2659
      @sjsjdsbsjjwjs2659 2 ปีที่แล้ว

      public class Solution {
      public static int minSubsetSumDifference(int[] nums, int n) {
      // Write your code here.
      int sum=0;
      for(int x:nums) sum+=x;
      int res=Integer.MAX_VALUE;
      for(int i=0;i

    • @prakharsoni7621
      @prakharsoni7621 ปีที่แล้ว

      Yes by adding this...
      for(int i=s;i>=0;i--)
      f(dp,n-1,i,arr);
      Your dp Array now fill perform the operation now :)

    • @harisrashid0773
      @harisrashid0773 ปีที่แล้ว

      yes we can but will give tle ;

  • @jeet7000
    @jeet7000 ปีที่แล้ว +4

    here's my recursive solution
    class Solution{
    public:
    int ans=1e8;
    int solve(int i,int arr[],int sum,int curr,int n,vector& dp){
    if(i==n){
    ans=min(ans,abs(curr-sum));
    return ans;
    }
    if(sum

    • @shadab9764
      @shadab9764 6 หลายเดือนก่อน

      Thanks man!

  • @ritikshandilya7075
    @ritikshandilya7075 22 วันที่ผ่านมา

    great solution , thanks striver

  • @stith_pragya
    @stith_pragya 6 หลายเดือนก่อน +1

    UNDERSTOOD............Thank You So Much for this wonderful video........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

    • @iamnoob7593
      @iamnoob7593 6 หลายเดือนก่อน

      man i just dont understand how is he able to do video recording at freakin 4 AM in the morning , Very few match that level of hardwork.

  • @maneeshapanu
    @maneeshapanu 10 หลายเดือนก่อน +3

    This code now is giving tle with one test case.

  • @PANKAJKUMAR-oy1hh
    @PANKAJKUMAR-oy1hh 2 ปีที่แล้ว +5

    i solved by finding value closer or equal to the half of total sum. but, i feel ur approach is more clear and concise.

    • @sameerbilla515
      @sameerbilla515 2 ปีที่แล้ว

      I did same, but cannot memoize it.. can you please tell how can I memoize it

  • @urvashi2410
    @urvashi2410 ปีที่แล้ว

    You made this really easy! Thanks

  • @koocheukkeijacky9704
    @koocheukkeijacky9704 8 หลายเดือนก่อน

    you are amazing teacher!

  • @katamsreeja6744
    @katamsreeja6744 ปีที่แล้ว

    understood it clearly. Thank you so much

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

    Greatly simplified!! Understood!!!!

  • @pratyushkumar8674
    @pratyushkumar8674 ปีที่แล้ว

    Understood 💯💯 Great Explanation.

  • @ratinderpalsingh5909
    @ratinderpalsingh5909 2 ปีที่แล้ว

    Understood, sir. Thank you very much.

  • @ramyasree4986
    @ramyasree4986 2 ปีที่แล้ว

    great idea of using tabulation of subset traget in finding ,minimum difference between sum of subets (crux: just we need is every possible target sum made by at least some subset or not )

  • @saimhatre89
    @saimhatre89 2 ปีที่แล้ว

    understood sir, thanks for making this so easy.

  • @AnandSagar1
    @AnandSagar1 ปีที่แล้ว +1

    God level explanation and content ❤‍🔥🔥

  • @jaydevkundu554
    @jaydevkundu554 ปีที่แล้ว

    Able to solve with just starting hints of 5min..
    Thank you striver..

  • @DevashishJose
    @DevashishJose 6 หลายเดือนก่อน

    thank you so much for your hard work

  • @rishabhbajpai6234
    @rishabhbajpai6234 ปีที่แล้ว

    understood ..........thanks for doing gret work sir

  • @okyanawangramadhana4879
    @okyanawangramadhana4879 2 ปีที่แล้ว

    Thanks for knowledge, sir!

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

    beautifully explained.

  • @harshpratapsingh1638
    @harshpratapsingh1638 2 ปีที่แล้ว

    you really make this question a piece of cake

  • @MohanaKrishnaVH
    @MohanaKrishnaVH 2 ปีที่แล้ว

    Awesome Explanation. Understood.

  • @riderpd09
    @riderpd09 2 ปีที่แล้ว

    understood clear as crystal :))

  • @gandhijainamgunvantkumar6783
    @gandhijainamgunvantkumar6783 2 ปีที่แล้ว

    Understood bhaiys. Thank you so much for your free and amazing content. :)

  • @113_manshi4
    @113_manshi4 ปีที่แล้ว

    Understood! Thank you so much!

  • @bhaktisharma9681
    @bhaktisharma9681 5 หลายเดือนก่อน

    understood sir!! thank you so much!

  • @pabitrakb5291
    @pabitrakb5291 8 หลายเดือนก่อน

    Understood
    Thank you

  • @saddy4420
    @saddy4420 ปีที่แล้ว

    US :)
    was trying to solve this question by myself but failed but once you said what dp[i][j] represent I immediately understood everything and solved it.

  • @chanchalroy3417
    @chanchalroy3417 6 หลายเดือนก่อน

    Just because of the previous lectures I was able to solve this problem without watching this lecture. Take a bow...
    Understood ❤

  • @sooyashjaju4208
    @sooyashjaju4208 ปีที่แล้ว

    Very much Intuitive ✨

  • @yuvyuvrajsingh2820
    @yuvyuvrajsingh2820 11 หลายเดือนก่อน

    Really appreciating work , your way of explanation🔥 , loved it bhai

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

    Understood, thank you.

  • @ObitoXuchiha942
    @ObitoXuchiha942 11 หลายเดือนก่อน +2

    We can have only sum/2+1 columns in our DP array. It also worked else it was giving TLE for 1 case. Love this playlist ❤❤

    • @himansh4812
      @himansh4812 10 หลายเดือนก่อน

      Yes. Only columns till totalsum/2 is required.

  • @nurzataltynbekova5594
    @nurzataltynbekova5594 ปีที่แล้ว

    Understood! Thank you!

  • @sunilswami6796
    @sunilswami6796 2 ปีที่แล้ว

    u r doing good work brother😌

  • @helloak7156
    @helloak7156 2 ปีที่แล้ว

    This was pure gold.