3201 & 3202. Find the maximum Length of Valid Subsequence i & ii | LeetCode Weekly Contest 404

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Hi, I am Amit Dhyani. Today, we solve two challenging problems from LeetCode's Weekly Contest 404.
    LeetCode 3201: Find the Maximum Length of Valid Subsequence I and LeetCode 3202: Find the Maximum Length of Valid Subsequence II.
    These problems are closely related to the classic Longest Increasing Subsequence (LIS) problem, which helps make the concepts easier to understand and solve. I'll guide you through the thought process, breaking down the problems step-by-step, and show you how to apply dynamic programming to find optimized solutions.
    Checkout my Segment Tree Playlist:
    • Segment Tree : Basic t...
    🌐 Connect with me:
    📧 Gmail: amitdhyani36@gmail.com
    💼 LinkedIn: / amit-dhyani-5164b8138
    📸 Instagram: / amit.dhyani.1
    #3201 #3202
    #leetcode #leetcodeweeklycontest #Coding #Programming #placementprep #jobseekers #cseducation #codingtutorial #leetcodedailychallenge #googleinterview #dynamicprogramming

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

  • @amit_dhyani
    @amit_dhyani  3 месяца назад +2

    Hey everyone! I'm planning new videos to go with my LeetCode content. What would you like to see next? I'm open to your suggestions
    1. Recent interview questions from top product based companies.
    2. GFG Problem of the Day (POTD)
    3. Codeforces and GeeksforGeeks contests
    4. SQL tutorials
    5. System design
    6. Any other suggestion

  • @princenagar1686
    @princenagar1686 3 месяца назад +2

    Best explanation on youtube, your approach and dry run was enough to solve the question, I coded it by seeing your dry run.

    • @amit_dhyani
      @amit_dhyani  3 месяца назад +1

      Dhanyawaad bhai

    • @princenagar1686
      @princenagar1686 3 месяца назад +1

      @@amit_dhyani bro contest ke 3rd or 4th question ke solution ka video zaroor dala karo, your explanations are good👍

    • @amit_dhyani
      @amit_dhyani  3 месяца назад +1

      Abse pure kosis karunga 🙏

  • @Authenticbharatiya
    @Authenticbharatiya Месяц назад +1

    really good explanation

  • @Ralish_Unfiltered
    @Ralish_Unfiltered Месяц назад +1

    trying to find the solution jo easily samajh aa jaye!!!!!!Aaj jake mila thankyu so much bhai.

  • @womenincodeplusplus4388
    @womenincodeplusplus4388 Месяц назад +1

    This is super. You are so much better than others . You should have more subscribers I believe.

  • @asmitshukla4649
    @asmitshukla4649 3 месяца назад

    bhaiya iska recursive code to samjhao, direct tabulation kyu samjha diya??

  • @shatulbansal4756
    @shatulbansal4756 2 месяца назад

    Great video and explanation bro!! Kudos!! :)
    Please keep it up and keep making more videos on weekly contests and daily Leetcode ques as much as possible, much needed :)

  • @sourabh2659
    @sourabh2659 2 месяца назад

    Best

  • @waltstone5445
    @waltstone5445 3 месяца назад +1

    Actually good explanation...I came here after watching 3-4 vids but this was the best. Thanks ❤

  • @abcd76820
    @abcd76820 3 месяца назад

    thankyou i am also finding LIS approach but no one has uploaded that . Thankyou

  • @priyankdixit4139
    @priyankdixit4139 3 месяца назад

    good

  • @himanshuchahar5374
    @himanshuchahar5374 3 месяца назад +3

    Best explanation ever, tried many different channels but didn't understand this question.But your's explanation is by far the best.
    Thanks Amit bhaiya.

  • @priyeshtandel2101
    @priyeshtandel2101 3 месяца назад +3

    Your explanation for this question is the best for me in this question, Thank you so much.😇

  • @princenagar1686
    @princenagar1686 3 месяца назад

    You should upload videos of contest solution from now on because nobody explains this clearly

  • @pp15155
    @pp15155 2 месяца назад

    very nice solution and yu explained very nicely thanku so much

  • @undextered
    @undextered 3 месяца назад +2

    Thanks for the awesome explanation, watched 5 videos but could not understand. Thanks to you I finally understood what's going on. Keep making up the good content.

  • @edu_ka9274
    @edu_ka9274 3 месяца назад

    Hello dhyani alok this side ASVJ DO U REMEMBER??

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      Han panday ji

    • @edu_ka9274
      @edu_ka9274 3 месяца назад

      @@amit_dhyani ni Bhai alok singh

  • @AkshatMaheshwari-wm1yg
    @AkshatMaheshwari-wm1yg 3 месяца назад +2

    Great explaination please upload video of all contests from now.🥰

  • @gangstacoder4234
    @gangstacoder4234 3 месяца назад

    isnt first solution from dp is unoptimized

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      We cannot say unoptimised.
      But yes a better solution of order n*k is also possible ( i guess you are referring this ? Better when k is comparatively much less than n)
      I explained this approach because we can easily correlate with LIS.

  • @shristisrivastava7054
    @shristisrivastava7054 2 месяца назад

    Best explanation. Thank you for making this video. Looking forward to your videos on the upcoming LeetCode questions.

  • @viditvaish7317
    @viditvaish7317 2 месяца назад

    bahut hi zayda amazing explanation ek dum crystal clear ho gaya sir , baaki kaafi jigah dekha pr samajh nahi aaya aap se ek baar me samajh aa gaya . please sir leetcode weekly aur biweekly contest pr videos banaya kariye sir .hume bahut zaroorat hai aise easily understandable solutions ki .great work sie keep going

    • @amit_dhyani
      @amit_dhyani  2 месяца назад

      Bahut bahut Dhanyawaad bhai.
      Me pure kosis karunga ki har contest and weekly contest ki time se video banane ki.
      Checkout leetcode weekly contest 405 explanation.
      Problem 4: ruclips.net/video/wG7DdEE3R4A/видео.htmlsi=doGFjb_-dsZg9BqW
      Problem 3: ruclips.net/video/YAZGYbO5l1w/видео.htmlsi=BCvu5yH9Cn7Q0M8l
      Problem 2: ruclips.net/video/_-s_LSx77jI/видео.htmlsi=CxcijTZ-B_sEvKvi

  • @Wondershu-r7f
    @Wondershu-r7f 3 месяца назад +2

    🙂sir you are great

  • @gurvindersingh136
    @gurvindersingh136 3 месяца назад

    Could you if possible provide the memorization code for the 3202 problem

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      @@gurvindersingh136 hey gurvinder, did you got the intuition ?
      Are you able to connect this problem with LIS ?
      If yes, then try to write the code by yourself.
      You can easily get the code from chatgpt or you can ask anyone you will get the code.
      But when you will do it by yourself, you will learn a lot.
      May be you will get stuck, the number of problem you solved may be less but you will learn a lot. You will learn when you will get stuck.
      If you are stuck, treat it as a opportunity, to learn.
      Actually code is already in video, but i recommend, if you got the intuition, then try to write it by yourself.
      If you stuck at any place put the code in comment, i will definitely give you hints to improve the mistake.
      But at the end you have to complete the code by yourself. That will be the correct approach to prepare for the interview.

    • @gurvindersingh136
      @gurvindersingh136 3 месяца назад

      @@amit_dhyani yes amit i got the idea and able to mapped it with the lis, so for the memo part I just need to change the greater than part with the mod. value that's it?

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      @gurvindersingh136 nice,
      Yes you are correct you just need to change that condition and thats it.
      Instead of increasing condition,
      Now you need to check whether to append or not according to updated condition.
      In lis if append is possible then max length will be
      Max( dp[arr[j]] +1 , dp[arr[i]])
      In this one if append is possible then max length will be
      Max( dp[arr[j]][mod] +1 , dp[arr[i]][mod])
      The code is at 29:00

    • @gurvindersingh136
      @gurvindersingh136 3 месяца назад

      @@amit_dhyani yes i got this point but I'm getting confused on how we intialize our mod vairable in the code , I tried something like below
      int rec(int i,int j,int k,vector&nums,vector&dp){
      if(i==nums.size()) return 0;
      if(dp[i][k]!=-1) return dp[i][k];
      int ans=1;
      for(int k=0;k

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      See in the rec function you took variable k in the loop and the variable k is already in function call. Which is causing the problem
      and also in the maximumLength function you increment i instead of j.
      int rec(int i, int j, int k, vector& nums, vector& dp) {
      if (dp[i][j] != -1) return dp[i][j];
      int ans = 1;
      for (int p = 0; p < i; p++) {
      int mod = (nums[i] + nums[p]) % k;
      if (mod == j) ans = max(ans, 1 + rec(p, mod, k, nums, dp));
      }
      return dp[i][j] = ans;
      }
      int maximumLength(vector& nums, int k) {
      int n=nums.size();
      vectordp(n,vector(k,-1));
      int ans=INT_MIN;
      for(int i=0;i

  • @kumkumslab5811
    @kumkumslab5811 3 месяца назад +1

    very good explaination dear
    sometimes i confuesd that even top competetive programmers not able to explain in this simplicities
    so one thing that we learn
    that you're not a king , but you are a king maker !!

  • @prateekjaiswal8045
    @prateekjaiswal8045 3 месяца назад +2

    You never know which video can give you massive increase in subscribers and likes. Hats off to you man amazing video.
    Earlier I was trying with memoization and was making (N*N*K) giving me TLE but you explained brilliantly.
    Liked and subscribed.

  • @amrutaparab4939
    @amrutaparab4939 14 дней назад

    Bohot Badhiya bhaiya

  • @artifice_abhi
    @artifice_abhi 3 месяца назад

    it is giving TLE:
    class Solution {
    public:
    int maximumLength(vector& nums) {
    int n = nums.size();
    vector dp(n , vector(2 , 1));
    int maxi = 0;
    for(int i = 0; i

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      Yes bro that’s why i mentioned the optimised approach for 3201 please refer 30:04.
      3202 can be solved easily using this way but we can optimised 3201.

  • @ashish3487
    @ashish3487 3 месяца назад +1

    maza aaya bhaiya .. just subscribed ur channel and liked your video

  • @AdityaGarg-hl7ri
    @AdityaGarg-hl7ri 3 месяца назад

    GREAT solution bro

  • @dhaneshwaridobriyal2943
    @dhaneshwaridobriyal2943 3 месяца назад

    Great solution ❤❤

  • @Nisha-yu3sj
    @Nisha-yu3sj 3 месяца назад

    Good ❤❤

  • @pradeepdobriyal4738
    @pradeepdobriyal4738 3 месяца назад

    Superb ❤

  • @prakhargarg4166
    @prakhargarg4166 3 месяца назад

    where is part 2

    • @amit_dhyani
      @amit_dhyani  3 месяца назад

      Bro both the solution is in the same video
      Refer 28:48
      First i introduced when modulus is 2 (leetcode 3201)
      Then you need to just change 2 with ‘k’ in code (leetcode 3202). Refer 28:48
      One more optimised approach for leetcode 3201 at the end.