Target Sum | Two Ways Of Memoization | Detailed | Leetcode 494 | Explanation + Code

Поделиться
HTML-код
  • Опубликовано: 2 янв 2025

Комментарии • 59

  • @India_mera_sabkuch
    @India_mera_sabkuch 8 дней назад +18

    sir me to itna hi kahana chahunga or har baar kahna chahungA YOU are the best sir....!! aap jese logo ko upar aana chahiye aap 70 k nhi 700k desreve karte hain!!

    • @codestorywithMIK
      @codestorywithMIK  8 дней назад +4

      This means a lot to me ❤️🙏

    • @manthansharma6769
      @manthansharma6769 7 дней назад +2

      Yeah dude , hes great
      but why only 700k xD LOL

    • @gui-codes
      @gui-codes 7 дней назад +1

      @@manthansharma6769 Must be Millions right 😍

  • @B-Billy
    @B-Billy 8 дней назад +14

    Solved this question my own after doing "We have a choice" technique of yours.
    But was strugling to prepare dp as 'exp' could be negative. Your 'map as a dp' technique is just WOOW!

  • @gui-codes
    @gui-codes 8 дней назад +10

    Easy done today MIK. Thank you.
    Please also continue DP on grids.

  • @rickdutta942
    @rickdutta942 8 дней назад +6

    23:37 This is called integer normalization method. It is used in count sort when encounted negetive values.

  • @ShubhamSingh-dz2ug
    @ShubhamSingh-dz2ug 8 дней назад +5

    i just love the part where you motivate 💚

  • @motivationalquotes8545
    @motivationalquotes8545 7 дней назад

    2nd way of memoization, just blow my mind 🙌🔥

  • @knightmare8718
    @knightmare8718 8 дней назад +9

    Bro MIK can you explain leetcode 3235 . I think it's one of the really good questions on graph

  • @_PRANAYMATE
    @_PRANAYMATE 8 дней назад +2

    Mik bhaiyya DP ka playlist karna baki hai abhi but aapki recursion playlist kar raha tha usi ke knowledge se DP ka question solve kar diya

  • @gui-codes
    @gui-codes 8 дней назад +17

    MIK, when do you rest

  • @yatheshtpoonia9225
    @yatheshtpoonia9225 7 дней назад +2

    Please never stop making videos

  • @prasadagalave9762
    @prasadagalave9762 8 дней назад +4

    Hey mik today I just found that you can build 2d map like unordered_map t;
    And we can push value just like array t[index][sum] = plus + minus;

    • @codestorywithMIK
      @codestorywithMIK  8 дней назад +1

      Yes you are absolutely right! That’s a great way 🙏❤️

  • @masterLight313
    @masterLight313 8 дней назад +2

    Bruh I admire your persistence!! Damn you are an inspiration!!

  • @vivekgupta_3085
    @vivekgupta_3085 7 дней назад +2

    Good Explaination

  • @Believe_yourself-eo1ho
    @Believe_yourself-eo1ho 8 дней назад +1

    Today POTD is solved before this video seen I flow you DP CONCEPT AND QUESTION WALA PLAYLIST PLEASE CONTINUE THIS PLAYLIST AS SOON AS POSSIBLE

  • @RayeesAli-p8f
    @RayeesAli-p8f 8 дней назад +1

    really amazing bhaiya ❤❤

  • @HeetVichhivora
    @HeetVichhivora 8 дней назад +6

    did this on my own , though easy one

    • @India_mera_sabkuch
      @India_mera_sabkuch 8 дней назад

      han but memoization dry run hota to jyada samjh aat abhi nhi aa rha!!

    • @HeetVichhivora
      @HeetVichhivora 8 дней назад

      @@India_mera_sabkuch megativwe index wala chiz he bas alag , aur bhaiya s + kar rhe hai index me aap 1000 bhi plus kar sakte ho according to constraints

  • @SaurabhSinghyadav-r4y
    @SaurabhSinghyadav-r4y 8 дней назад +1

    That's something amazing bhaiya ❤

  • @floatingpoint7629
    @floatingpoint7629 8 дней назад +1

    superb explanation as always btw you do not need memoization the constraints are low enough

    • @codestorywithMIK
      @codestorywithMIK  8 дней назад

      You're right! ❤️
      For this problem, memoization isn't necessary because of the constraint size. But it's a good practice for larger problems.

  • @it047_prakhar8
    @it047_prakhar8 7 дней назад +1

    bhaiya ❤❤❤ today is a very special day .. idk aapko yad h ki nhi mne ek comment kiatha ki darr lag rha h bhaiya kahin placement lagegi ki nhi and a lot of things apne kaha tha ho jaiga ...
    aaj finally ho gya , finally got placed , interviewer was genuinely impressed by my problem solving skills aur m besharmo ki tarah 100 percent apki copy kar rha tha wahan . apki videos se daily potd karta hu bohot kuch sikha h aapse aur bhi bohot kuch sikhna baki h . last 1.5 years se daily apko follow karta hu aur karta rahunga

    • @codestorywithMIK
      @codestorywithMIK  7 дней назад

      Wow. Many Many Congratulations 🎊🎊❤️❤️
      So happy to hear this.

  • @parthasarma-r4x
    @parthasarma-r4x 6 дней назад

    The sum can actually be -1, hence when you are filling it with the default value of -1 we would ignore some of the memoized values, the correct default value for the memoized array/list should be -1 * (sum of nums +1)

  • @siddhantswarupmallick6710
    @siddhantswarupmallick6710 8 дней назад +4

    Noice explanation!!!!!!!

  • @vaibhav454
    @vaibhav454 8 дней назад +4

    Discuss bottom up and space optimized code also

  • @Its_Shubham_Negi
    @Its_Shubham_Negi 8 дней назад +2

    first 🔥

  • @aadityaraj2397
    @aadityaraj2397 7 дней назад

    sir , contest ka bhi question karaiye n , please 🙏🙏

  • @vikashkansotiya2139
    @vikashkansotiya2139 8 дней назад +1

    I am passing mostly tests for placements, and getting shortlist for interviews. But I am not able to pass interview till now, sometime after HR round i am getting rejected. I am not giving up, but somewhere my mind is getting it that interview are hard for me. definitely I will never give up in future on anything and i cant give up. But i want to pass the interview now. I will be getting interviews in January, mostly interviewers are saying that explanation is the problem.
    can you make 2-3 videos on interviews related your experience. It will be helpful.

  • @bhushanambhore8378
    @bhushanambhore8378 7 дней назад +1

    Hi MIK, you didn't posted approach-1 using map in Java on Github..

  • @vishwashsoni610
    @vishwashsoni610 8 дней назад +3

    this is how i solved this question sir :
    class Solution {
    public:
    int n;
    int t[21][2001];
    int solve(int i,vector& nums,int target){
    if(i >= n){
    if(target == 0){
    return 1;
    }
    else{
    return 0;
    }
    }
    if(target>=0){
    if(t[i][target] != -1){
    return t[i][target];
    }
    }
    else{
    if(t[i][abs(target)+1000] != -1){
    return t[i][abs(target)+1000];
    }
    }
    int take = solve(i+1,nums,target-nums[i]);
    int notTake = solve(i+1,nums,target);
    if(target>=0){
    return t[i][target] = take + notTake;
    }
    return t[i][abs(target)+1000] = take + notTake;

    }
    int findTargetSumWays(vector& nums, int target) {
    n = nums.size();
    int totalSum = 0;
    for(auto& num : nums){
    totalSum += num;
    }
    if(target > abs(totalSum) || (totalSum+target)%2 != 0){
    return 0;
    }

    int newtarget = (totalSum+target)/2;
    memset(t,-1,sizeof(t));

    return solve(0,nums,newtarget);
    }
    };

  • @nihalsingh6233
    @nihalsingh6233 8 дней назад +1

    Sir can you please explain the tc ??
    I am getting confused why it is O(n * sum(nums))

  • @AmarjeetKumar-to9ub
    @AmarjeetKumar-to9ub 7 дней назад +2

    🔥++

  • @priyadarshangarg1051
    @priyadarshangarg1051 3 дня назад +1

    I did solve these problems but I can't build the intuition ......

  • @LaumerFrieda
    @LaumerFrieda 7 дней назад

    Thanks for sharing such valuable information! Could you help me with something unrelated: I have a SafePal wallet with USDT, and I have the seed phrase. (alarm fetch churn bridge exercise tape speak race clerk couch crater letter). How can I transfer them to Binance?

  • @DevanshGupta-io7rl
    @DevanshGupta-io7rl 8 дней назад +3

  • @Redxplayss
    @Redxplayss 8 дней назад +1

    first watch

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 8 дней назад +2

    public int findTargetSumWays(int[]nums,int target){
    int sum=Arrays.stream(nums).sum();
    if(sum=num;++i)
    dp[i]+=dp[i-num];
    return dp[target];
    }
    one query many yutuber say that in 2025 ma hiring ma dsa ka weighted kam hoga and development ka weighted jayada hoga?🎉❤

  • @rickdutta942
    @rickdutta942 8 дней назад +2

    14:12 😂 Code hai ya Bomb.

  • @AjaySoni-u6w
    @AjaySoni-u6w 8 дней назад

    Tabulation bhi bata dete sir !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @unknown47896
    @unknown47896 7 дней назад +1

    bro could you plz solve leetcode question number 3398 if u have time

  • @PremKumar-hm4lw
    @PremKumar-hm4lw 8 дней назад

    sir please solve leetcode problem no. 2127

  • @ihm101
    @ihm101 8 дней назад

    hey can you do 3348 on leetcode once

  • @Aryan-cy7cu
    @Aryan-cy7cu 8 дней назад +1

    Memoization , every time I mispronounce this word 😅

  • @rohanmandal369
    @rohanmandal369 7 дней назад

    Memoization samajh nahi aata, please make few videos to help us understand memoization

    • @codestorywithMIK
      @codestorywithMIK  7 дней назад

      Try DP concepts playlist where I have explained these in details.
      Link - ruclips.net/p/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt&si=XkEKTsJXXNv-gF3c
      Hope this helps ❤️🙏

  • @masterLight313
    @masterLight313 8 дней назад +1

    I have doubt in word ladder 2 question, everything fits here for a graph and bfs approach with relation on connection with 1 letter off and queue up with the paths, but i always get MLE, memory limit issue. Other vids are there are with the wildcards, can you make a video on this?

  • @joydeep-halder
    @joydeep-halder 7 дней назад +2

    I solved this problem at first glance super easily because of you bhaiya ❤. But was not able to memoize and was scratching my head. The moment you say that currSum can go negative, I got instant thought to shift the range. I did t[index][currSum + 1000) and was thinking super proud that I cracked it. But after you told that we can even optimize the space more, Hats off bhaiya 🔥🔥. It can never be possible that we will not learn something new in every video. 🫡