3251. Find the Count of Monotonic Pairs II | Weekly Leetcode 410

Поділитися
Вставка
  • Опубліковано 8 лис 2024

КОМЕНТАРІ • 27

  • @sagnikbiswas3268
    @sagnikbiswas3268 2 місяці тому +7

    Common pattern in LeetCode contests - prefix sums DP.

    • @vkfanclub12
      @vkfanclub12 2 місяці тому

      Can you show me similar problems

  • @amitguptapc
    @amitguptapc 2 місяці тому +1

    Amazing solution man. It took me some time to understand the values of l and r, but finally understood after doing with pen and paper. Its nice that u leave some blank spaces so that we can think, instead of spoon feeding. Keep growing.👍👍👍

  • @MamunHossain-j5c
    @MamunHossain-j5c 2 місяці тому +1

    Excelent Explanation Thanks a lot. also thanks to clear why I need to think in a bottom up approach. #kudus #salute and #respect.

  • @nabhirajjain8149
    @nabhirajjain8149 2 місяці тому

    very nice explanation, thanks

  • @ucanhly1166
    @ucanhly1166 2 місяці тому

    Can you tell me about your pratice strategy from beginner to leetcode master ?

  • @selvaragavan_10
    @selvaragavan_10 2 місяці тому

    please xplain how you are handling the overflows. Why you are adding the mod while getting the range sum.

    • @codingmohan
      @codingmohan  2 місяці тому +1

      For overflows - I am making sure I take mod on every addition so that the number never goes beyond given MOD.
      Why I am subtracting - because every number is modulus M, the left part can be smaller than the right. And you cannot use negative number with mod, hence I added mod (as adding mod is equal to adding zero if you take MOD).

  • @omkumarjha2745
    @omkumarjha2745 2 місяці тому

    Super Explanation . Thanks a lot.

  • @chaitanya812
    @chaitanya812 2 місяці тому

    Can you also explain the last problem from the biweekly 136 contests last problem that is using tree rerouting[DP on Trees] would love to see your explanation on that topic :)

  • @GauravDuseja-t6q
    @GauravDuseja-t6q 2 місяці тому

    Thanku bhaiya very good explanation

  • @anshulsharma3137
    @anshulsharma3137 2 місяці тому +1

    bro great explanination. Just a request, can you please use dark mode for these notes, it really hurts the eyes

    • @codingmohan
      @codingmohan  2 місяці тому

      I started with full black but based on feedback I changed.
      The issue is that in black background, the free colors doesn't works well.

  • @arjunreddy2647
    @arjunreddy2647 2 місяці тому

    do we actually save time when we take out the prv2 parameter since it’s dependent on the first 2 anyways?

    • @codingmohan
      @codingmohan  2 місяці тому

      We do because previously we would have to compute more states. Another way to visualize is - look at the 3D dp vs 2D dp).

  • @kkkkkkkkkk811
    @kkkkkkkkkk811 2 місяці тому

    Bhaiya biweekly bhi discuss kr do please

  • @vamsikrishnagannamaneni912
    @vamsikrishnagannamaneni912 2 місяці тому

    l = max(prv1, nums[i] - prv2)
    I didnt understand why we are doing this
    why to include prv1?

    • @codingmohan
      @codingmohan  2 місяці тому

      Because the condition in the first array needs to be satisfied as well.
      In the recursion look at the starting index of the loop.

    • @vamsikrishnagannamaneni912
      @vamsikrishnagannamaneni912 2 місяці тому

      @@codingmohan Why max though? if the loop in recursion is starting from prv1, why cant it just be prv1(l = prv1)
      everything excluding this part was clear.
      I am gonna have to rewatch this multiple times.

    • @codingmohan
      @codingmohan  2 місяці тому +1

      There is a "if" condition in the loop. Try to think into that direction

  • @39_jatinjain4
    @39_jatinjain4 2 місяці тому

    in the end solution was not good just you made 2d into 1d

    • @codingmohan
      @codingmohan  2 місяці тому +1

      Sorry I didn't realise that it could be a long jump.
      For you to help - you can simply code the entire thing in 2D version and then you will realise that you are only using the previous index values itself. Try that once.

    • @39_jatinjain4
      @39_jatinjain4 2 місяці тому

      No, i got the intuition this is just a space otmization but wanna complete first with 2d dp

  • @39_jatinjain4
    @39_jatinjain4 2 місяці тому

    can anyone provide optimization of this using 2d DP-class Solution {
    public:
    int mod = 1e9 + 7;
    int dp[2001][1001];
    int countOfPairs(vector& nums) {
    int n = nums.size();
    memset(dp,0,sizeof(dp));
    for(int p1=0;p1=0;idx--){
    for(int p1=0;p1= 1 ? nums[idx-1]-p1 :1000);
    for (int i = p1; i = val) {
    ans = (ans + dp[idx + 1][i]) % mod;
    }
    }
    dp[idx][p1]=ans;
    }
    }
    return dp[0][0];
    }
    };

  • @cosmicboy588
    @cosmicboy588 2 місяці тому

    int countOfPairs(vector& nums)
    {
    int n = nums.size();
    vector dp(n,vector(1001,0));
    for(int i = 0; i

  • @atulrai1187
    @atulrai1187 2 місяці тому

    bhai last 10 min khud bolke khud smjh liya aapne