Number of Submatrices That Sum to Target | Subarray Sum Equals K | Leetcode 1074 | Leetcode 560

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 80th Video of our Playlist "Array 1D/2D Programming : Popular Interview Problems".
    In this video we will try to solve two very good Array problems -
    Subarray Sum Equals K (Leetcode 560)
    K Inverse Pairs ArrayNumber of Submatrices That Sum to Target (Leetcode 1074)
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : K Inverse Pairs ArrayNumber of Submatrices That Sum to Target | Subarray Sum Equals K | Leetcode 1074 | Leetcode 560
    Company Tags : Meta, Amazon, Netflix, Apple, Google, Amazon
    My solutions on Github(C++ & JAVA) :
    Leetcode - 560 - github.com/MAZHARMIK/Intervie...
    Leetcode -1074 - github.com/MAZHARMIK/Intervie...
    Leetcode-560 Link : leetcode.com/problems/subarra...
    Leetcode-1074 Link : leetcode.com/problems/number-...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Approach Summary (Leetcode-560) : The approach uses a map (mp) to keep track of cumulative sums encountered during the iteration through the input array. It initializes sum to zero and increments it as it iterates through the array. The map is used to store the count of each cumulative sum. The algorithm checks if the difference between the current cumulative sum (sum) and the target value (k) exists in the map. If it does, it adds the corresponding count to the result. Finally, the count of the current cumulative sum is updated in the map. The function returns the total count of subarrays with the sum equal to k.
    Approach Summary (Leetcode-1074) : The approach involves iterating through all possible starting and ending points (rows and columns) of submatrices within the given matrix. For each combination of starting and ending points, it calculates the sum of elements within the submatrix and increments the result count if the sum matches the target. The function returns the total count of submatrices with the sum equal to the target. This solution has a time complexity of O(m^2 * n^2), where 'm' is the number of rows and 'n' is the number of columns in the matrix. It can be optimized further using precomputation or dynamic programming techniques.
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    ✨ Timelines✨
    00:00 - Introduction
    00:31 - Leetcode-560 Problem Explained
    1:46 - Leetcode-560 Brute Force
    4:25 - Leetcode-560 Optimal Intuition with Dry Run
    16:53 - Leetcode-560 Live coding
    19:12 - Leetcode-1074 Problem Explained
    21:14 - Leetcode-1074 Brute Force
    24:46 - Leetcode-1074 Optimal Intuition with Dry Run
    51:25 - Leetcode-1074 Live coding
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear

Komentáře • 107

  • @codestorywithMIK
    @codestorywithMIK  Před 5 měsíci +57

    Apologies for the delay guys. I am packing for my next trip to Mussoorie.
    I hope you guys will like the explanation.
    Thank you all . Love you all ❤
    Because of the trip, Contest problems will be delayed this week 🙏

  • @user-ub2is4rs4x
    @user-ub2is4rs4x Před 5 měsíci +39

    It feels illegal to get this Dope content free of cost . Single handedly this guy is beating paid courses like scaler, gfg, bosscoder etc.
    Hats off legend.
    Enjoy the trip.

  • @malvikachoudhary4395
    @malvikachoudhary4395 Před 5 měsíci +11

    There are so many youtubers who are very famous for teaching DSA but your channel is super underrated. I wish I had started my preparation by learning from your videos. Great work!!! Love your consistency and hard work

  • @molyoxide8358
    @molyoxide8358 Před 5 měsíci +11

    Before watching MIK's video this question was very verty HARD.
    But after watching the dry-run it became too EASY.
    Thanks a lot MIK .

    • @codestorywithMIK
      @codestorywithMIK  Před 5 měsíci +2

      Means a lot brother ❤️❤️🙏🙏

    • @molyoxide8358
      @molyoxide8358 Před 5 měsíci +3

      @@codestorywithMIK Bhaiya pls aage bhi content ko free hi rakhna pls, aaplke wajah se hi mein pechle 1 saal se LC mein consistent hoon(solved 534 ques till now).

  • @Abhi_008
    @Abhi_008 Před 5 měsíci +5

    No matter how tough the questions in the daily challenge may be, I find confidence knowing that if I stumble, you're there to turn the challenge into a piece of cake. Grateful for your support!
    Thank You for this beautiful story.❣
    If you get time then please tell us a story of today's weekly contest problem - 2,3,4... ❣
    I was not able to solve question-2 :(

  • @adarshjha5126
    @adarshjha5126 Před 5 měsíci +14

    God level ❤

  • @ankit_yadav11
    @ankit_yadav11 Před 3 měsíci +1

    u r the legend u r the best god bless u big brother love you , whenever i watch ur content u made my day

  • @manishjoshi9737
    @manishjoshi9737 Před 5 měsíci +2

    ek bar m hi chal gya code wo bhi without any error ... kya gazab ka smjahaya boss ek Number..

  • @oqant0424
    @oqant0424 Před 5 měsíci +3

    I pray everyday to God for u...
    U r such a gem Bhaiya❤❤

  • @ugcwithaddi
    @ugcwithaddi Před 5 měsíci +1

    This channel is a treasure

  • @UECAshutoshKumar
    @UECAshutoshKumar Před 3 měsíci +2

    Thank you 👍

  • @bhuppidhamii
    @bhuppidhamii Před 5 měsíci +2

    never heard of `1 Q's ke saath 1 free!`
    thank, you're great work

  • @wearevacationuncoverers
    @wearevacationuncoverers Před 5 měsíci

    Legit explanation. Hats off

  • @gauravbanerjee2898
    @gauravbanerjee2898 Před 5 měsíci +3

    Was waiting for your video since moring 😁 thanks a lot bhaiya ❤❤ and wishing you a great trip to Mussoorie 🙌

  • @Santosh_Kumar6205
    @Santosh_Kumar6205 Před 3 měsíci +3

    when you approach a problem it really seems like story telling

  • @23cash86
    @23cash86 Před 5 měsíci +1

    22:00, i dint knew how to find all submatrix till now, surprising i did not knew it

    • @anshumaan1024
      @anshumaan1024 Před 5 měsíci +2

      mujhe bhi aaj hi pta chla bhai 😅🫂

  • @suyashjain3223
    @suyashjain3223 Před 3 měsíci +1

    Amazing Explanation!! 🔥🔥🔥

  • @Shauryacious
    @Shauryacious Před 3 měsíci +1

    WOW!!! best explaination possible

  • @user-sr5ov4zm8i
    @user-sr5ov4zm8i Před 5 měsíci

    such a great explanation ... Loved it , i have personally seen all the available explanation present for this question ,but no one has explained it so perfectly

  • @closer9689
    @closer9689 Před 3 měsíci +1

    I am grateful that I found your Channel💫.

  • @sauravchandra10
    @sauravchandra10 Před 5 měsíci

    Clear explanation!

  • @simply_arko
    @simply_arko Před 5 měsíci

    Once again god level explanation! 🔥🔥

  • @ashutoshchoubey369
    @ashutoshchoubey369 Před 5 měsíci +1

    That's some next level of explanation bro.

  • @EatCodeAndSleep
    @EatCodeAndSleep Před 5 měsíci

    thanks for this wonderful explanation and the best part of this video is the dry run and thanks for that too keep rocking.

  • @theOmKumar
    @theOmKumar Před 5 měsíci +1

    Thank you for your efforts :)

  • @riyanshbiswas
    @riyanshbiswas Před 5 měsíci +1

    If you hadn't made this video then I wouldn't have understood this question in a milliion years!

  • @aws_handles
    @aws_handles Před 5 měsíci

    Happy trip mik.
    Thank you for posting videos for us even during your trip ❤️❤️

  • @cse080chandrasekhar9
    @cse080chandrasekhar9 Před 5 měsíci +2

    waiting from morning nd wait is over now ❤

  • @09avishkargaikwad71
    @09avishkargaikwad71 Před 5 měsíci +1

    Hats off legend.
    Can you please make the video on today's GFG POTD "Geekina Hate 1's" ?
    I was able to tackle the problem with Brute Force but it required the more efficient approach. I think the optimized solution involves the Binary Search Algorithms which can reduce the range of numbers but I'm not able to code the actual logic for problem...
    @codestorywithMIK please make the vdo

  • @shambhojaybhaye2822
    @shambhojaybhaye2822 Před 5 měsíci

    whenever i was not able to solve the leetcode POTD then i always wait for your video. your are just op OP EXPLANATION ❤💝

  • @tutuimam3381
    @tutuimam3381 Před 5 měsíci +1

    Thanks 👍

  • @Abhay14
    @Abhay14 Před 5 měsíci

    Best CZcamsr ever

  • @souravjoshi2293
    @souravjoshi2293 Před 5 měsíci

    masterpiece explanation

  • @rushabhlegion2560
    @rushabhlegion2560 Před 5 měsíci

    Got it brother. Awesome.

  • @mohd.vaseem7410
    @mohd.vaseem7410 Před 5 měsíci

    sir you are amazign with your effort,hardwork, and in-depth explaination wish you luck in your field

  • @ashishxsoni
    @ashishxsoni Před 5 měsíci

    Your videos make me to do problems even if i know i stuck ti solve inner just try if not make it then mik is there ❤

  • @anuppatankar4294
    @anuppatankar4294 Před 5 měsíci

    Great video 👌

  • @oqant0424
    @oqant0424 Před 5 měsíci

    Have a safe & wonderful trip .

  • @shashanksharma136
    @shashanksharma136 Před 5 měsíci

    Thanks sir.

  • @cherrycharan2314
    @cherrycharan2314 Před 5 měsíci

    Thank you so much. You made it very clear and easy! Lots of love toward your concept, patience and explanation!!!

  • @xiaoshen194
    @xiaoshen194 Před 5 měsíci +5

    Yo mik bhaiya, would u be covering today's B and D from the weekly?

    • @codestorywithMIK
      @codestorywithMIK  Před 5 měsíci +5

      I am travelling. But let me try asap ❤️🙏

    • @xiaoshen194
      @xiaoshen194 Před 5 měsíci +3

      ​​@@codestorywithMIK Ok, safe travels❤❤

  • @sagargupta5135
    @sagargupta5135 Před 5 měsíci

    Thankyou sir

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak Před 5 měsíci

    🤩 clear

  • @devjindal1934
    @devjindal1934 Před 5 měsíci

    You explained it very well sir but you missed the 2D sum approach method which is famous for this question

  • @user-tz3ql5jd1n
    @user-tz3ql5jd1n Před 5 měsíci

    Before video problem very hard 😞
    After watching video very easy🎉😂❤

  • @user-nn5td7lw9k
    @user-nn5td7lw9k Před 4 měsíci +1

    387 weekly contests on leetcode question no. 2 solved due to this, question 😊

  • @oqant0424
    @oqant0424 Před 5 měsíci

    GOAT ✨✨

  • @ashutoshpandey1639
    @ashutoshpandey1639 Před 5 měsíci

    Hello Bhaiya, I urge you to make a video on today's gfg POTD , you are the only one who can explain that problem so that I can code it at my own.I have spend more than an hour on that problem but I can't get it

  • @Ramneet04
    @Ramneet04 Před 5 měsíci +1

    Yesterday's and today's questions were just 🤒

  • @manimanohar_001
    @manimanohar_001 Před 5 měsíci

    We're now 17k family.
    Bhadayi hi MIK bhaijaan🎉😊
    Bhai LC 2074 ek baar try kardo Bhai.

  • @subhajitdey135
    @subhajitdey135 Před 3 měsíci +1

    Bhaiya for the first problem , instead of inserting {0,1} in map for the first time, cant we check this with this code like : if(sum==0 ) count++; if(arr[i]==0) count++; ? Map me pehle insert karna intuition thoda hard laga, but it was worth it !!. Thanks for the content bhaiya ❤

  • @rishabh1406
    @rishabh1406 Před 5 měsíci

    Brother when you get time pls cover digit dp questions

  • @shabananoor9423
    @shabananoor9423 Před 5 měsíci

    🔥🔥

  • @knoxmacroboy7272
    @knoxmacroboy7272 Před 5 měsíci

    can u give us an insight on where to use a prefx sum type concept

  • @cameye9
    @cameye9 Před 5 měsíci +1

    Sir also make a solution video on today's leetcode weekely 382 contest of Q4 that is last Hard question using memoization becasue of that my today's day goes worse 😢. Also I am attatching my last Q4 answer below getting wrong answer in 551 testcase with memoization and got TLE in 613 testcase without memoization👇
    class Solution {
    private int solve(List list,int idx,int k,int[][] dp){
    if(k==0 || idx==list.size()-1){
    int min=Integer.MAX_VALUE;
    int ans=0;
    for(int i:list){
    ans|=i;
    }
    min=Math.min(min,ans);
    return min;
    }
    if(dp[idx][k]!=-1){
    return dp[idx][k];
    }
    int n1=list.get(idx);
    int n2=list.get(idx+1);
    list.remove(idx);
    list.remove(idx);
    list.add(idx,n1&n2);
    int take=solve(list,idx,k-1,dp);
    list.remove(idx);
    list.add(idx,n2);
    list.add(idx,n1);
    int skip=solve(list,idx+1,k,dp);
    return dp[idx][k]=Math.min(take,skip);
    }
    public int minOrAfterOperations(int[] nums, int k) {
    int[][] dp=new int[nums.length+1][k+1];
    for(int i=0;i

  • @vinayaksinghal
    @vinayaksinghal Před 5 měsíci

    Bhaiya,whenever possible please make a video on today's leetcode challenge. Unn questions ke solutions yt pe kaheen nahi hain

  • @ShivamMishra-fo1wx
    @ShivamMishra-fo1wx Před 5 měsíci

    sir please explain gfg hard level potd questions also

  • @Harshit_Soni_
    @Harshit_Soni_ Před 5 měsíci

    Bhaiya please make videos on contest problems also

  • @codeandtalk6
    @codeandtalk6 Před 5 měsíci

    ❤❤❤

  • @anuragkhard
    @anuragkhard Před 5 měsíci

    Suggestion, change the channel name to something fancy will help you to grow (Insiders update)

  • @bhuppidhamii
    @bhuppidhamii Před 5 měsíci

    19:21 main thing

  • @manimanohar_001
    @manimanohar_001 Před 5 měsíci +4

    Bro with your permission shall I post this video's link in my solution??

    • @codestorywithMIK
      @codestorywithMIK  Před 5 měsíci

      Yes please ❤️❤️🙏🙏

    • @user-ub2is4rs4x
      @user-ub2is4rs4x Před 5 měsíci

      I always share his videos almost everywhere 😅

    • @manimanohar_001
      @manimanohar_001 Před 5 měsíci

      @@codestorywithMIK bro pls share your LC profile so that I can put that in the credit. 🙏

  • @upcoming_Engineer_
    @upcoming_Engineer_ Před 3 měsíci

    Thank You for this amazing video bhaiya...
    but i have one doubt:
    in code of second question we don't have any loop for startRow so we will get only those submatrix which contains first row always. so we won't get answer for the other submatrix which doesn't contains first row....
    but your code is accepted.......How?
    please clear my doubt bhaiya or anyone, it will be very helpful.

  • @subhamcoder
    @subhamcoder Před 5 měsíci +1

    sir high quality per video record kijiya

  • @ChiragWadwa
    @ChiragWadwa Před 5 měsíci +3

    can someone share the 2D array kadane problem number?

    • @codestorywithMIK
      @codestorywithMIK  Před 5 měsíci

      github.com/MAZHARMIK/Interview_DS_Algo/blob/master/DP/Maximum%20Sum%20Rectangular%20Submatrix%20in%20Matrix%20dynamic%20programming(2-D%20kadane).cpp

  • @factinsaan4333
    @factinsaan4333 Před 5 měsíci

    Bhaiya plz do Q4 of today's contest

  • @Himanshusharma-ph6no
    @Himanshusharma-ph6no Před 5 měsíci

    Bhaiya please make a solution of leetcode weekly contest 382 last question solution 3022 question number

  • @abc-ym4zs
    @abc-ym4zs Před 5 měsíci

    bhaiya is how to learn development in interview persecptive bhaiya

  • @harshtiwari416
    @harshtiwari416 Před 5 měsíci

    bhai aajke leetcode contest ki video aayengi kya??

  • @omkarjadhav848
    @omkarjadhav848 Před 3 měsíci

    bhaiya sliding window wali playlist banana ek.

    • @codestorywithMIK
      @codestorywithMIK  Před 3 měsíci

      czcams.com/play/PLpIkg8OmuX-J2Ivo9YdY7bRDstPPTVGvN.html&si=U4TluXjpHMNmeSKS
      Will upload more on this soon.

  • @top_g755
    @top_g755 Před 5 měsíci

    Sir gfg ka potd kra do please

  • @kundankumar-zl3qq
    @kundankumar-zl3qq Před 5 měsíci

    First viewer

  • @Lucifer0872
    @Lucifer0872 Před 5 měsíci +1

    Hail Mary brother

  • @rounakkamble9408
    @rounakkamble9408 Před 5 měsíci

    Mik bhaiyaa gfg potd 😢

  • @user-pi2zd4xj8z
    @user-pi2zd4xj8z Před 3 měsíci +1

    I joined ur watsapp

  • @nish0798
    @nish0798 Před 5 měsíci

    @codestorywithMIK bhai ek doubt hai bipartite graph ke question mein leetcode 785, 886 dono question mein jab hum adj list banale hai from 2d matrix toh ek question toh uske 2 ways hai both have same logic but kiss
    LEETCODE 886- THIS WAY OF ADJACENCY LIST WORKS
    ArrayList gra=new ArrayList();
    for(int i=0;i

  • @rohitshah8904
    @rohitshah8904 Před 5 měsíci

    The way of explaining is just 🔥 🫡