Leetcode 1937 Maximum Number of Points with Cost

Sdílet
Vložit
  • čas přidán 17. 07. 2021
  • Third problem from Leetcode Weekly Contest 250
    Problem Links :
    Leetcode 1937 : leetcode.com/problems/maximum...
    Leetcode 1014 : leetcode.com/problems/best-si...
    Leetcode 931 : leetcode.com/problems/minimum...
    Contest Link :
    leetcode.com/contest/weekly-c...
    Solution Links :
    Leetcode 1937 : github.com/Sandip-Jana/Youtub...
    Leetcode 1014 : github.com/Sandip-Jana/Youtub...
    Leetcode 931 : github.com/Sandip-Jana/Youtub...
    Explanation : github.com/Sandip-Jana/Youtub...
    Hope you learned something from this video. Do not forget to like and subscribe this channel :)
    #Sandip Jana
    #sandip jana
    #sandip_jana
    #Leetcode
    #weekly contest 250

Komentáře • 57

  • @auto8ot644
    @auto8ot644 Před 2 lety +5

    I really like how you explained the question using Leetcode 931 and 1014 as support to explain 1937. Thanks for the video!

  • @rohithkumargattu6749
    @rohithkumargattu6749 Před 3 lety +1

    Thank you so much! It is a great explanation, sir, definitely I am gonna share this video and channel with all my friends to watch, it is really helpful. please solve the problems consistently, definitely, it will help lots of people and this channel definitely gonna rock

  • @nurshuvo3854
    @nurshuvo3854 Před 2 lety

    Thanks man. I like the way you explained.

  • @user-zi1sr6uc7b
    @user-zi1sr6uc7b Před 24 dny

    Nice Explanation, thanks

  • @motivation_hubPJ
    @motivation_hubPJ Před 3 lety

    Very nice explanation thanks a lot !

  • @mitasingh1553
    @mitasingh1553 Před rokem

    if it is abs diff. then it will always return a positive value then why j< k or j>k matters?

  • @aviralarpan7350
    @aviralarpan7350 Před rokem

    Thanks a lot

  • @harshalgarg1149
    @harshalgarg1149 Před 3 lety

    Thanks a lot.

  • @srndrpec
    @srndrpec Před rokem

    one shot, three problems...good approach

  • @cyrusthapa794
    @cyrusthapa794 Před rokem

    Too Great ! XD

  • @ujjvalsharma5055
    @ujjvalsharma5055 Před rokem

    great explanation. Keep up with the good work

  • @nipunaggarwal7568
    @nipunaggarwal7568 Před 3 lety

    Sir, amazing explanation

  • @rupayanghosh150
    @rupayanghosh150 Před 3 lety

    Great explanation

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk Před 2 lety

    Great Explanation, thank you

  • @vamshisagargadde1629
    @vamshisagargadde1629 Před 10 měsíci

    very good explanation.

  • @paragroy5359
    @paragroy5359 Před 2 lety

    Nice explanation.........thanks for the video...

  • @shayranadilse1005
    @shayranadilse1005 Před rokem

    You are op🎉🎉

  • @ankurshah3112
    @ankurshah3112 Před 2 lety

    Very good explanation. Thank you

  • @Adrian-xe2sn
    @Adrian-xe2sn Před 2 lety

    Could you potentially explain how you got case 2 : -j < k? Like why is it -j?

    • @sandip_jana
      @sandip_jana  Před 2 lety

      No No. I wrote it as
      Case 2 :- j < k
      Its not -j haha sorry for the trouble :)

  • @souravadhikari7485
    @souravadhikari7485 Před 2 lety

    Can you please explain
    rightMax[m-1] = dp[i-1][m-1] - (m-1);
    Why do we take -(m+1) part in your code?

    • @sandip_jana
      @sandip_jana  Před 2 lety +1

      Its simple :
      the state is :
      --> dp[i-1][k] - k
      so when k == m-1
      we will have
      --> dp[i-1][m-1] - (m-1)
      we simply replace k with m-1. because the last column is denoted by m-1

  • @AnkitKumar-po4wx
    @AnkitKumar-po4wx Před 3 lety

    nice explanation

  • @chetansahu1505
    @chetansahu1505 Před 3 lety +1

    @3:50 I stopped the video here and went to solve leetcode 931 (nicely done in one go) and leetcode 1014 as well (realized I solved it earlier). I got some ideas to handle now 1937 but still in a little muddle.

    • @sandip_jana
      @sandip_jana  Před 3 lety

      Ok thanks for feedback. So where exactly do you have doubts? Which part of the problem you didn't understand?

    • @blasttrash
      @blasttrash Před 2 lety

      @@sandip_jana link not working

    • @sandip_jana
      @sandip_jana  Před 2 lety

      Hi. Yes it wont work. let me know if you have any specific doubts. i will try to answer them here

    • @sandip_jana
      @sandip_jana  Před 2 lety

      github.com/Sandip-Jana/CZcams/blob/main/MaximumNumberOfPointsWithCost.txt

  • @nribackpacker
    @nribackpacker Před 2 lety

    very good explanation appreciated

  • @yhdzhang
    @yhdzhang Před 2 lety

    Thanks. Really good explanation. My question is how am I meant to come up with these math equations if I haven't seen the question before

    • @sandip_jana
      @sandip_jana  Před 2 lety +1

      Good question! Actually this comes with practice . the more problems we solve the better we become

  • @dsacp7570
    @dsacp7570 Před 3 lety

    today i solved sightseeing one, got stuck in contest though for this.

  • @TheIndianChroniclee
    @TheIndianChroniclee Před 2 lety

    Very Nice Explaination ..

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk Před 2 lety +1

    Such a great way to tackle DP write mathematical equations and then break it apart.

  • @chetansahu1505
    @chetansahu1505 Před 3 lety

    Many people like me come on CZcams, post leetcode contest to help themselves upsolve the unsolved problems. So if you could make videos of all 4 problems after every contest that would be of great help. Thanks brother for such a great explanation.

    • @sandip_jana
      @sandip_jana  Před 3 lety +3

      I will try. I am still struggling to explain properly in my videos as evident from the bloopers :D . But yeah i will try :)

  • @gururajchadaga
    @gururajchadaga Před 9 měsíci

    what about the case j == k?

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk Před 2 lety +1

    Came back to it in the morning, I am still failing to understand that how it is O(nm)

    • @ShivangiSingh-wc3gk
      @ShivangiSingh-wc3gk Před 2 lety

      Don't we have to do all the values of k

    • @sandip_jana
      @sandip_jana  Před 2 lety

      Correct we have to do it for all values of k. and what does k signify??
      Case 1 : j > k
      so k = ( 0,1,.... j-2 , j-1 )
      Case 2 : j < k
      so k = ( j+1 , j+2 ..... m-1 )
      So k is the number of columns we have.
      So for each row we simply precompute the leftPrefixMaximum for all values of `k`.
      And the rightSuffixmaximum for all values of `k`.
      Finally we calculate the best answer for all current row.
      Hence time complexity = O( n * ( m + m + m ) ) ~ O ( n*m )
      Let me know if you have any doubts
      Solution for reference : github.com/Sandip-Jana/CZcams/blob/main/Leetcode1937.java

  • @vardhanyash243
    @vardhanyash243 Před 14 dny

    noice

  • @RG-yj4cb
    @RG-yj4cb Před 2 lety +1

    todu ho bhai, 15 min teen questions chaap diye!

  • @ishaankaustav727
    @ishaankaustav727 Před 2 lety

    💚💚

  • @HarendraKumar-hl8nh
    @HarendraKumar-hl8nh Před 3 lety

    Sir, Please upload beautiful problems on Dp and please continue teaching on white board. 🙏🙂 I am eagerly waiting... for your upcoming videos on Dp.

  • @BRBallin1
    @BRBallin1 Před 2 lety +1

    Sorry but I didn't understand the problem still based on your explanation. It focused too much on the notations but should've done a walkthrough with the logic directly per iteration

    • @sandip_jana
      @sandip_jana  Před 2 lety

      No worries. I am trying to explain in a better way

  • @shaikhkamran532
    @shaikhkamran532 Před 2 lety

    best of what? when you explain explain it clearly please

    • @sandip_jana
      @sandip_jana  Před 2 lety +1

      I am trying to improve my explanation. You may try to read other explanations in the discussion forum of problem for better idea. Hope that helps.

  • @ankitmishra399
    @ankitmishra399 Před rokem

    hey can u optimize memiozed approach code attach below

    • @ankitmishra399
      @ankitmishra399 Před rokem

      class Solution {
      Long dp[][];
      public long maxPoints(int[][] mat) {
      long max=0;
      dp=new Long[mat.length][mat[0].length];
      for(int j=0;j