3201, 3202. Find the Maximum Length of Valid Subsequence II | | Math | DP | LIS Similar

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • In this video, I'll talk about how to solve Leetcode 3202. Find the Maximum Length of Valid Subsequence II | 3201. Find the Maximum Length of Valid Subsequence I | Math | DP | LIS Similar
    LIS Concept - • Find the Longest Valid...
    Code for top down code (same as what we discussed in video) - leetcode.com/problems/find-th...
    [and yeah, as we are having i, j, & prevRem] - thus complexity will be O(n*n*k)
    Let's Connect:
    📱Discord (Join Community) : / discord
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / codewitharyanbhai
    💻 Twitter - / aryan_mittal007
    🤖 Github: github.com/aryan-0077
    About Me:
    I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Timelines✨
    0:00 -Bakwas
    2:35 - Building up Intuition for Leetcode 3201
    7:22 - LC 3201 Explanation
    11:22 - Code Explanation
    13:16 - Another way to solve LC 3201 (curRem, prevRem, curRem) form
    20:16 - LC 3202 Explanation, Code & Dry Run Explample
    24:34 - LC 3202 Top-Down approach thinking (Code in Description)
    31:06 - Space Optimised O(k) Solution
    37:10 - Like thok dena
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Komentáře • 33

  • @justarandomguy6106
    @justarandomguy6106 Před 27 dny +5

    i also tried the recursive memoize approach TC-> O(k^2 *n) and i got MLE.

  • @atheisth2373
    @atheisth2373 Před 26 dny +4

    not understood

  • @SurbhiGoyal-v4h
    @SurbhiGoyal-v4h Před 27 dny +1

    This solution is incredible! good work!

  • @cameye9
    @cameye9 Před 28 dny +5

    What I was thinking in first at the time of contest is using recursive with memoization and it is good to go and solved both Q2 & Q3 but when I used memoization it gives memory limit exceed error i both the cases and My submission is left with just last 10 cases in both the Questions and due to that I was stuck on these Questions in my whole leetcode contest and that actually ruined/fucked up my mind totally. My question is that to you Aryan that how we should think out like these approaches at the time of contest because in my mind apart from memoization no other approached come .

    • @sanketchugh294
      @sanketchugh294 Před 27 dny

      He is been doing this for many years now. It's all about consistent practice and evolving yourself with different approaches

    • @cameye9
      @cameye9 Před 25 dny

      @@sanketchugh294 Thank you I didn't know this before.

  • @umangbehl8152
    @umangbehl8152 Před 24 dny +1

    this is a complex explanation usually if a tutor explains in a complex way i dry run by myself to understand what he is saying but in this video i have to rewatch some of the section again and again to understand

  • @jade-zc2bz
    @jade-zc2bz Před 27 dny +8

    i cant understand 🥲

  • @rafeeqm
    @rafeeqm Před 28 dny

    great video Aryan

  • @Ayush37262
    @Ayush37262 Před 28 dny +2

    Bhai 1st wali bhi thodi tricky thi

  • @ajayprabhu465
    @ajayprabhu465 Před 25 dny +1

    aryan cant understand this, idk why, first the first time feeling very bad

  • @princenagar1686
    @princenagar1686 Před 26 dny +13

    Aryan Mittal read it positively please => you are under misconception that you are simplifying problem, but you are actually overexplaining everything which is actually harder to understand than it actually should.
    My suggestion => Try to focus on what i said and try to see that in your videos. You can explain to only those actually don't need explanations, that's where comes tricky part that if someone already know intution then he will think that you are explaining very good, and if he doesn't know approach then he will think that he himself need to improve because of your over justifying things, rather you should just simplify problem to everyone like it force them to think that actually problem was too easy, that's where youtubers like Striver, Love babbar, CodeWithHarry , chai aur code , etc, shines and you do not even come close to them.

  • @princenagar1686
    @princenagar1686 Před 26 dny +2

    12:08 don't explain code we are not machines, explain approach with dry runs, and please take it positively and you will shine on youtube in the world of coding.

  • @hritikanand9734
    @hritikanand9734 Před 28 dny +3

    🫡

  • @udaymourya7322
    @udaymourya7322 Před 28 dny +1

    My memoization java code runs ->
    class Solution {
    int dp[][];
    int kk;
    public int maximumLength(int[] nums, int k) {
    int n = nums.length;
    kk = k;
    dp = new int[n+1][k+1];
    for (int[] d1 : dp) {
    Arrays.fill(d1, -1);

    }
    int ans = 0;
    for(int i=n-1; i>0; i--){
    for(int j=i-1; j>-1; j--){
    ans = Math.max(ans , 2 + solve(nums , j , (nums[j] + nums[i]) % kk)); //finding first two elements.
    }
    }
    return ans;
    }
    public int solve(int[] nums, int pre, int mod) {
    if (pre == -1) return 0;
    if (dp[pre][mod] != -1) return dp[pre][mod];
    int ans = 0;
    for (int i = pre-1; i >= 0; i--) {
    if ((nums[i] + nums[pre]) % kk == mod) {
    ans = Math.max(ans, 1 + solve(nums, i, mod));
    break;
    }
    }
    dp[pre][mod] = ans;
    return ans;
    }
    }

  • @yashwairagade3677
    @yashwairagade3677 Před 28 dny +1

    suggestion if possible remove top down section as it is so much confusing rest other is awesome

    • @rafeeqm
      @rafeeqm Před 28 dny +1

      completely disagree, it's for the intuition

  • @Robinkumar-ew9ky
    @Robinkumar-ew9ky Před 28 dny +1

    Today's problem to upload karo jaldi
    Remove Graph edges

    • @Jazzimus
      @Jazzimus Před 28 dny +2

      check their community post

    • @Robinkumar-ew9ky
      @Robinkumar-ew9ky Před 28 dny +3

      @@Jazzimus
      I checked it already in morning but unfortunately I thought it is only hint so I didn't click on it and I couldn't see the video link.
      Thanks .

  • @HindiDubbedReels
    @HindiDubbedReels Před 15 dny +1

    Bhai hindi me bol liya kro nhi dekhra koi bahr ka tume vo discussion section se samajh kete ha

  • @Shashank-e3x
    @Shashank-e3x Před 27 dny

    Bro please accept my connection request !!

  • @yashwairagade3677
    @yashwairagade3677 Před 28 dny

    optimization of 3202 freezed my brain

  • @soumyapadhy3414
    @soumyapadhy3414 Před 28 dny +3

    First why r u elaborating all the stuffs which is very much irritating secondly u r teaching to graduate student not a kg school child

    • @rafeeqm
      @rafeeqm Před 28 dny

      Not everyone watching is a graduate student

    • @khushal7363
      @khushal7363 Před 27 dny +1

      dude if see his hard problem explanation he make them look damn easy by this style and skip the simple part i usually do that and watch at 1.5-1.75.

  • @Shashank-e3x
    @Shashank-e3x Před 27 dny

    Bro please accept my connection request !!

    • @ARYANMITTAL
      @ARYANMITTAL  Před 27 dny

      Bro full name to bata dete🥲, how will i search just Shashank ❤️