Range Sum Query 2D - Immutable - Leetcode 304 - Python

Ғылым және технология

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
Problem Link: leetcode.com/problems/range-s...
0:00 - Read the problem
1:15 - Drawing Explanation
7:31 - Coding Explanation
leetcode 304
#coding #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.

Пікірлер: 39

  • @blossombabalola1234
    @blossombabalola12342 жыл бұрын

    Thank you Neet. This concept is a bit difficult to explain but you did a good job!

  • @Mad7K
    @Mad7K2 жыл бұрын

    To be honest at the start I thought I was completely off the mark, but that's exactly how I solved it, thanks for the video.

  • @mohammedafzal4343
    @mohammedafzal4343 Жыл бұрын

    At first, it was a little tough to understand, but I watched this video multiple times. Now I fully understood the concept! thanks Neetcode!

  • @kariuki6644
    @kariuki66442 жыл бұрын

    My first time hearing about prefix sum but this made it easier to understand

  • @aishwaryaranghar3385
    @aishwaryaranghar33852 жыл бұрын

    Really liking the strategy of posting videos on the streak day!!

  • @SkyeTian
    @SkyeTian Жыл бұрын

    I understand why we are adding a top row since it would be out of bounds when we are calculating prefix sum for the first row (no "above"), but why are we also adding a left column?

  • @programmermainul6558
    @programmermainul65582 жыл бұрын

    It would be great video. I am jumping on this r8 now. Cheers!

  • @ainazikmomunalieva3732
    @ainazikmomunalieva37322 жыл бұрын

    Thank you! You are a master at explaining!

  • @krishnalath1266
    @krishnalath12662 жыл бұрын

    Thank You for such a wonderful explanation....

  • @amosluesun585
    @amosluesun585 Жыл бұрын

    this is fabulous, nice work

  • @hinatahyuga3038
    @hinatahyuga30382 жыл бұрын

    thank you so much sir, took me 3 hours to understand it

  • @dabobrotosarkar7266
    @dabobrotosarkar72662 жыл бұрын

    Hey Neet! You explain great! I love your videos. Can you make a video about Problem 307. Range Sum Query - Mutable? It uses Segment Trees to optimize the algorithm. Would love to see that!

  • @user-op1xk2yz8d
    @user-op1xk2yz8d9 ай бұрын

    you're de besttttt....Thank youuuuu

  • @pulakammalathy6968
    @pulakammalathy6968 Жыл бұрын

    cant we compute the prefix matrix in place of the given matrix ?

  • @monadastar9393
    @monadastar93932 жыл бұрын

    thank you so much

  • @b9944236
    @b9944236 Жыл бұрын

    Tanks a lot ~

  • @firomsamt7642
    @firomsamt76426 ай бұрын

    mind blowing!👏

  • @jasdeepsinghgrover2470
    @jasdeepsinghgrover24702 жыл бұрын

    This can be generalized to all shapes with vertical or horizontal edges... Then we can apply inclusion exclusion principle

  • @vasujain1970
    @vasujain19702 жыл бұрын

    Interesting video.

  • @DK-ox7ze
    @DK-ox7ze Жыл бұрын

    What's the logic behind calculating prefix sum for each cell? What's the intuition behind the formula you used?

  • @rahulkhatoliya6814
    @rahulkhatoliya68142 жыл бұрын

    crystal clear

  • @spyboy0076
    @spyboy00762 жыл бұрын

    I don't know what will i do. I can't think of anything while solving these problems

  • @staffeng

    @staffeng

    2 жыл бұрын

    I think the only way is to first solve enough problems by learning through videos like this in a systemic manner, like going from one topic to another, practicing them again from memory, and then attempting enough new problems on our own till we are able to solve most of the unseen mediums. This is going to take an insane amount of time but for those like us who are not naturally gifted at this, I think it's the only way. @NeetCode - can you create a video on how you got to a stage where you can solve unseen mediums or hards?

  • @gunahawk6893

    @gunahawk6893

    2 жыл бұрын

    @@staffeng great 👏

  • @VidyaBhandary
    @VidyaBhandary2 жыл бұрын

    Awesome ....

  • @sahaiabhishek
    @sahaiabhishek6 ай бұрын

    Excellent

  • @mohithadiyal6083
    @mohithadiyal60832 жыл бұрын

    No doubt , great video as usual 😀

  • @kirillzlobin7135
    @kirillzlobin71356 ай бұрын

    Amazing

  • @reapergrim5324
    @reapergrim532413 күн бұрын

    Line 10 : above = matrix[i][j+1] How is this above it should be right ?

  • @krateskim4169
    @krateskim41692 жыл бұрын

    nice

  • @Nisha.......
    @Nisha.......2 жыл бұрын

    Sir, will you please solve leetcode 174?

  • @rajsuriyang3427
    @rajsuriyang34272 жыл бұрын

    one-liner: The time limit is exceeding, Why? return sum([sum(self.matrix[i:row2+1][0][col1:col2+1]) for i in range(row1,row2+1)]) Can you explain?

  • @sirmidor

    @sirmidor

    Жыл бұрын

    Because you're completely ignoring what the exercise asks: What you typed is not O(1) time complexity for getting a region's sum. Your matrix indexing is also less than optimal: You're already looping over range(row1, row2 + 1), so you would just take self.matrix[i] instead of unnecessarily doing self.matrix[i:row2+1][0] to get a row of the matrix.

  • @theghostwhowalk
    @theghostwhowalk2 жыл бұрын

    Great video. Mind helping with similar video on Range sum mutable 308 which has update func. Would be great to understand Index tree implementations.

  • @onepiece1570
    @onepiece15702 жыл бұрын

    go

  • @robertlemiesz7143
    @robertlemiesz71433 ай бұрын

    I would honestly never ask this in an interview. Kinda feels like you either have seen the problem and know the answer, or need to take significant amount of time deriving it. Tells you nothing about the candidate, except whether or not they do alot of leet code.

  • @shambhavi6888
    @shambhavi68882 ай бұрын

    🥹

  • @johnvick8861
    @johnvick88619 ай бұрын

    within a min i understood .

Келесі