Coding Interview Question | Max size square submatrix with all 1s | Dynamic Programming

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024

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

  • @prashantgiri1285
    @prashantgiri1285 3 года назад +4

    Can I get a recursive approach?

  • @ashpreetsinghanand7260
    @ashpreetsinghanand7260 2 года назад

    class Solution {
    public:
    int solve(vector &matrix, int i, int j, int &maxans, vector &dp){
    if(i>=matrix.size() || j>=matrix[0].size()){
    return 0;
    }
    if(dp[i][j]!=-1){
    maxans = max(maxans, dp[i][j]*dp[i][j]);
    return dp[i][j];
    }
    int diagonal = solve(matrix, i+1, j+1, maxans, dp);
    int right = solve(matrix, i, j+1, maxans, dp);
    int down = solve(matrix, i+1, j, maxans, dp);
    if(matrix[i][j]=='1'){
    int ans = 1 + min(diagonal, min(right, down));
    maxans = max(maxans, ans*ans);
    return dp[i][j] = ans;
    }
    else{
    return dp[i][j] = 0;
    }
    }
    int maximalSquare(vector& matrix) {
    int a = matrix.size();
    int b = matrix[0].size();
    int maxans=0;
    vector dp(a+1, vector(b+1, -1));
    solve(matrix, 0, 0, maxans, dp);
    return maxans;
    }
    };

  • @sarcastic5561
    @sarcastic5561 5 месяцев назад

    best the way u just make us understand by dry running the crux of the questions its all what we need for any questions thankyou !!

  • @AR-scorp
    @AR-scorp 4 года назад +3

    I really like your Dynamic Programming series. Helped me understand the algos, and without looking at your code, I was able to write the code myself, even with space optimization by using two rows.
    Thanks for the videos.

  • @ChristForAll-143
    @ChristForAll-143 11 месяцев назад

    Hope i would have a girl friend like you, very good explanation
    Thank you

  • @55_jyotirmaykar30
    @55_jyotirmaykar30 2 года назад

    Excellent video ma'am. You are way more greater than I am capable of admiring.🙏🙏🙏🙏

  • @suvai_kitchen
    @suvai_kitchen 3 года назад

    Excellent video. at least i found a video who explains the intuition and logic of how solution works. Other videos just jump to solution and make us accept that.
    But what made you to think that the side of every square formed must be stored in another dp matrix? What brought you this thought?

  • @aniketpathak6623
    @aniketpathak6623 4 года назад +1

    Thanks for such clear explanation of the Algorithm. Please do continue this series of DP. 😊

    • @KeertiPurswani
      @KeertiPurswani  4 года назад +1

      Thanks Aniket. Going to continue this series for sure :)

  • @laxman1225
    @laxman1225 2 года назад

    Thanks for the wonderful explanation.
    How to come up with these ideas other than practice?

  • @makeupby.ananya
    @makeupby.ananya 3 года назад

    How would we find which element of the dp table is our answer for the entire matrix? Like how would we get the answer as 3?

  • @manojjain3501
    @manojjain3501 2 года назад

    I liked as you It mean a lot to you. :) . Excellent explanation.

  • @kannanparamasivam5331
    @kannanparamasivam5331 4 года назад +1

    Simple and clear explanation. Appreciate your effort!!!

  • @_YaelRobert
    @_YaelRobert 4 года назад +1

    Thanks Keerti for the good explanations! Your efforts to help us in understanding DP are highly appreciated! Thanks a lot :)
    Your videos are getting better than before. Keep it up!!

  • @rapakavineethkumar5429
    @rapakavineethkumar5429 3 года назад

    Excellent video, I solved this question before but never thought of this solution. I am watching all of your videos now.

  • @vibhu613
    @vibhu613 2 года назад

    great video ------tonnes of love didi

  • @yawar110
    @yawar110 3 года назад

    what if we want to find the max sub metrics with all 0s instead?

  • @AmanSingh-pq4rf
    @AmanSingh-pq4rf 9 месяцев назад

    Great explanation

  • @sanchitmehra1079
    @sanchitmehra1079 3 года назад

    Very nice explanation :)

  • @ashutoshjadhav
    @ashutoshjadhav 4 года назад +1

    Nicely explained ^_^

  • @devprakash5320
    @devprakash5320 3 года назад

    Naice solution

  • @arnobchowdhury9641
    @arnobchowdhury9641 3 года назад

    Thanks a lot. Liked and Subscribed right when you said it means a lot to you.

  • @tejasghone5118
    @tejasghone5118 4 года назад

    Great explanation!! White board explanations really simplify things.

  • @sukdebdasthakur6749
    @sukdebdasthakur6749 4 года назад

    On which CTC?

  • @sakshibhalothia8770
    @sakshibhalothia8770 4 года назад

    Can you pls tell me why you're taking minimum when we have to find maximum?

    • @KeertiPurswani
      @KeertiPurswani  4 года назад +3

      Because all the 3 values should be 1 to form a square, even if one isn't, then it won't be square so you take minimum
      Please try to go through the video once more. This is exactly what I tried to explain 😅

    • @sakshibhalothia8770
      @sakshibhalothia8770 4 года назад +1

      @@KeertiPurswaniGot it!!!😅 Thank you so much

  • @vigneshhendrix4447
    @vigneshhendrix4447 4 года назад

    You just Nailed it !🔥 I got the logic now. Thank yu !

  • @KurtVanBever
    @KurtVanBever 3 года назад

    Very nice presentation and explanation 👍

  • @shankar7662
    @shankar7662 3 года назад

    Nice Explanation!!

  • @sukdebdasthakur6749
    @sukdebdasthakur6749 4 года назад

    On which company you are working? Please reply.

    • @KeertiPurswani
      @KeertiPurswani  4 года назад

      Presently at Intuit. You can check on LinkedIn as well :)