Leetcode Weekly Contest 402 | Video Solutions - A to D | by Abhinav Kumar | TLE Eliminators

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • Here are the video solutions for problems A, B, C, D of Leetcode Weekly Contest 402. We hope this will be useful for you in up-solving this contest.
    📢Check out handpicked problems by Priyansh himself, on our CP-31 sheet: www.tle-eliminators.com/cp-sheet
    Solution Codes:
    Problem A : leetcode.com/problems/count-p...
    Problem B : leetcode.com/problems/count-p...
    Problem C : leetcode.com/problems/maximum...
    Problem D : leetcode.com/problems/peaks-i...
    Be sure to check out TLE Eliminators.
    Website: www.tle-eliminators.com/
    Instagram: / tle_eliminators
    Linkedin: / tle-eliminators
    Twitter: / tle_eliminators
    TLE Community Discord Server: / discord
    Timestamps:-
    0:00 Problem A
    3:30 Problem B
    15:37 Problem C
    35:49 Problem D

Komentáře • 35

  • @TLE_Eliminators
    @TLE_Eliminators  Před měsícem +1

    Please fill the feedback form: forms.gle/kYqtzVfTFbVUwzm37

  • @ds_rocks5108
    @ds_rocks5108 Před měsícem +16

    The 3 rd question was tough since conventional memomization solution didnt work

    • @SHIVAMSINGH-bl1hk
      @SHIVAMSINGH-bl1hk Před měsícem

      i also did the same...but got Memory limit exceeded 533/553 test case passed

    • @dawodujohnson
      @dawodujohnson Před měsícem

      Use array instead of vector

  • @RishavTheCoder
    @RishavTheCoder Před měsícem +5

    please buy some good quality microphones

  • @tinkuvishnu795
    @tinkuvishnu795 Před měsícem +5

    Please Post last weekly and last biweekly solutions

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i Před měsícem +2

    Thankyou for the solutions !

  • @aryanrawat3494
    @aryanrawat3494 Před měsícem +1

    ❤❤loved it 🔥 🔥

  • @mojammelhaquebhuiyan4648
    @mojammelhaquebhuiyan4648 Před měsícem

    why we don't need to consider power[i] + 1, and power[i] + 2 for dp[i] ?

  • @justvibing9663
    @justvibing9663 Před měsícem +1

    I got 3 wrong submissions in 3rd question Came back to lc after 3months😓

  • @NotHuman-bc1cc
    @NotHuman-bc1cc Před měsícem

    Nice one!!

  • @roshangeorge97
    @roshangeorge97 Před měsícem +1

    can someone break down the 2nd question the modulo arithmetic part?

    • @sss-rn4oy
      @sss-rn4oy Před měsícem +2

      So he basically created frequency map from 0 to 23, where he stores value he faced % 24, why modulo is being used is basically makes things here easier, like if we have 12 and it can be paired with 12, 36... so if we just make % 24 for them we will only deal with 12 in this case. So from here map from 0 to 23, the only thing to consider is 24 itself it will be treated as 0 in our map.
      Required one is the (24 - (hours[i] % 24)) with extra % 24 to deal with case where 24 comes out.
      Very helpful will be rewatching and proving everything on paper for yourself, peace!

    • @musaddikkhan9720
      @musaddikkhan9720 Před měsícem

      Consider in this way
      (a + b ) % k where k is any number
      according to modulo rule (a + b) % k can also be written as (a % k + b % k ) % k
      now think in this case where we have two number (a + b) % k = 0 that means any two number whose come in the table k it's remainder will be the zero now if we mod any number with if it'll come in (0 - k-1) range (e.g... 50 % 24 = 2 or 2 % 24 == 2 ) now here is the acutal logic come i have two number ( a % 24 + b % 24) if it's sum become 0 or 24 so our answe also the divisble by 24
      our a%24 alwasy < 24 (that means it's come in 0 - 23) now check any two number
      if i have (a % 24) == 6 then what will be the (b % 24 ) it' must be the 24 - 6 = 18 a ny number remainder is 18 that'll divisible by 24 (eg my orignal a either (6, 30 , 54 ) when you divide this number by 24 the remainder will always 6 and our orignal number b will be either(18 , 42, 66) if you divide this by 24 the remainder will be the 18 ) now add any two number from a & b the answer i always divisble by 24
      I hope you'll understand it now

  • @user-nx9jh6uo2d
    @user-nx9jh6uo2d Před měsícem

    Sir..How you thought that it will be 1d dp..as i thought i can take index and the last index chosen as variables..it would be 2d dp..and just memoized it..but it got tle...Sir is it wrong that we have to take x d dp if there are total x variables changing with every state..

    • @user-nx9jh6uo2d
      @user-nx9jh6uo2d Před měsícem

      #define ll long long int
      class Solution {
      public:
      long long maximumTotalDamage(vector& nums) {
      mapm;
      int n=nums.size();
      for(int i=0;i

  • @devatal3767
    @devatal3767 Před měsícem

    @9:36 how freq[6]++; ? can anyone help

    • @roshangeorge97
      @roshangeorge97 Před měsícem

      6%24 = 6, so freq[6]++, but ig there was a mistake.. we need to search for 24-6 ie: 18. so for the element 6 it should be freq[18++]//..

    • @nishanttyagi3665
      @nishanttyagi3665 Před měsícem

      do you want to know what does freq[6]++ means

    • @devatal3767
      @devatal3767 Před měsícem

      @@roshangeorge97 I also thought that

    • @abhinavkumariitism
      @abhinavkumariitism Před měsícem

      @@roshangeorge97 We r calculating out answer using *ans+=freq[req]* , where *req=(24-a[j]%24)%24* , and then we r updating *freq[a[j]%24]++*
      what it means is, when we have a[j]=6, we will check req=24-6=18, so we will search for frequency of 18 in our freq array, and update our answer.. then, we will do *freq[6]++* , to update our frequency array.
      and, when we come to 18.. we will get req=24-18=6, so we update answer using ans+=freq[6], and then update freq[18]++
      I hope that is clear. If not, u can look at the code again and try to dry run yourself.

  • @adarshkumarjha2097
    @adarshkumarjha2097 Před měsícem

    atleast invest in good mics

  • @jagan5785
    @jagan5785 Před měsícem +1

    in 3rd question inner loop will run at max 3 times , isn't it??

  • @medotarun1952
    @medotarun1952 Před 26 dny

    time to change the tutor I think....

  • @YashSharma-qs1ph
    @YashSharma-qs1ph Před měsícem +1

    class Solution {
    public long maximumTotalDamage(int[] power) {
    return f(0,new HashMap(),power);
    }
    public long f(int i,Map map,int p[])
    {
    if(i>=p.length)
    return 0;
    long nottake=f(i+1,map,p);

    long contain=0,max=0,take=0;
    if(map.containsKey(p[i]))
    take=0+f(i+1,map,p);
    else{
    map.put(p[i]-2,1);
    map.put(p[i]-1,1);
    map.put(p[i]+2,1);
    map.put(p[i]+1,1);

    take=p[i]+f(i+1,map,p);
    map.remove(p[i]-2);
    map.remove(p[i]-1);
    map.remove(p[i]+2);
    map.remove(p[i]+1);
    }

    max=Math.max(take,nottake);
    return max;
    }
    } can we do 3rd question like this logic is simple values which we cant take store in map so that after going forward we cant take that value

    • @Mmk-gi4ug
      @Mmk-gi4ug Před měsícem

      This may give MLE because of the map

    • @YashSharma-qs1ph
      @YashSharma-qs1ph Před měsícem

      @@Mmk-gi4ug why it will give mle explain

    • @abhinavkumariitism
      @abhinavkumariitism Před měsícem +1

      the TC of this code would go exponential, as u have not done any memiozation here.. its simply recursivve brute force.

    • @YashSharma-qs1ph
      @YashSharma-qs1ph Před měsícem

      @@abhinavkumariitism it will optimise easily using 1dp I know but I want to know it will work

    • @vigneshs1852
      @vigneshs1852 Před měsícem

      does it give MLE for you...

  • @Abhay14
    @Abhay14 Před měsícem

    bhaiya maine c question me map nhi set use kiya tha but error de diya 338 testcases pass ho gya but submit nhi hua can you tell me why this approach fails ???
    class Solution {
    public:
    void insertInStack(int n, set&st){
    for(int i=n-2; i