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

  Рет қаралды 36,630

NeetCode

NeetCode

Күн бұрын

🚀 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
@blossombabalola1234 2 жыл бұрын
Thank you Neet. This concept is a bit difficult to explain but you did a good job!
@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!
@Mad7K
@Mad7K 2 жыл бұрын
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.
@kariuki6644
@kariuki6644 2 жыл бұрын
My first time hearing about prefix sum but this made it easier to understand
@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?
@aishwaryaranghar3385
@aishwaryaranghar3385 2 жыл бұрын
Really liking the strategy of posting videos on the streak day!!
@programmermainul6558
@programmermainul6558 2 жыл бұрын
It would be great video. I am jumping on this r8 now. Cheers!
@dabobrotosarkar7266
@dabobrotosarkar7266 2 жыл бұрын
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!
@krishnalath1266
@krishnalath1266 2 жыл бұрын
Thank You for such a wonderful explanation....
@ainazikmomunalieva3732
@ainazikmomunalieva3732 2 жыл бұрын
Thank you! You are a master at explaining!
@pulakammalathy6968
@pulakammalathy6968 Жыл бұрын
cant we compute the prefix matrix in place of the given matrix ?
@hinatahyuga3038
@hinatahyuga3038 2 жыл бұрын
thank you so much sir, took me 3 hours to understand it
@jasdeepsinghgrover2470
@jasdeepsinghgrover2470 2 жыл бұрын
This can be generalized to all shapes with vertical or horizontal edges... Then we can apply inclusion exclusion principle
@amosluesun585
@amosluesun585 Жыл бұрын
this is fabulous, nice work
@DK-ox7ze
@DK-ox7ze Жыл бұрын
What's the logic behind calculating prefix sum for each cell? What's the intuition behind the formula you used?
@spyboy0076
@spyboy0076 2 жыл бұрын
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 👏
@user-op1xk2yz8d
@user-op1xk2yz8d 9 ай бұрын
you're de besttttt....Thank youuuuu
@reapergrim5324
@reapergrim5324 10 күн бұрын
Line 10 : above = matrix[i][j+1] How is this above it should be right ?
@monadastar9393
@monadastar9393 2 жыл бұрын
thank you so much
@firomsamt7642
@firomsamt7642 6 ай бұрын
mind blowing!👏
@b9944236
@b9944236 Жыл бұрын
Tanks a lot ~
@vasujain1970
@vasujain1970 2 жыл бұрын
Interesting video.
@rahulkhatoliya6814
@rahulkhatoliya6814 2 жыл бұрын
crystal clear
@Nisha.......
@Nisha....... 2 жыл бұрын
Sir, will you please solve leetcode 174?
@sahaiabhishek
@sahaiabhishek 6 ай бұрын
Excellent
@VidyaBhandary
@VidyaBhandary 2 жыл бұрын
Awesome ....
@kirillzlobin7135
@kirillzlobin7135 6 ай бұрын
Amazing
@mohithadiyal6083
@mohithadiyal6083 2 жыл бұрын
No doubt , great video as usual 😀
@rajsuriyang3427
@rajsuriyang3427 2 жыл бұрын
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
@theghostwhowalk 2 жыл бұрын
Great video. Mind helping with similar video on Range sum mutable 308 which has update func. Would be great to understand Index tree implementations.
@krateskim4169
@krateskim4169 2 жыл бұрын
nice
@robertlemiesz7143
@robertlemiesz7143 3 ай бұрын
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.
@onepiece1570
@onepiece1570 2 жыл бұрын
go
@shambhavi6888
@shambhavi6888 2 ай бұрын
🥹
@johnvick8861
@johnvick8861 8 ай бұрын
within a min i understood .
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 352 М.
Find All Anagrams in a String - Leetcode 438 - Python
12:14
NeetCode
Рет қаралды 77 М.
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 23 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 39 МЛН
LOVE LETTER - POPPY PLAYTIME CHAPTER 3 | GH'S ANIMATION
00:15
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 7 МЛН
Range Sum Query Immutable - Leetcode 303 - Python
7:42
NeetCodeIO
Рет қаралды 13 М.
Range Sum Query 2D | Leetcode #304
15:39
Techdose
Рет қаралды 10 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 280 М.
Sum Query in 2D Immutable Array Dynamic Programming
18:34
Tushar Roy - Coding Made Simple
Рет қаралды 50 М.
Sum of All Subsets XOR Total - Leetcode 1863 - Python
18:26
NeetCodeIO
Рет қаралды 9 М.
Sparse Table & RMQ (Range Minimum Query)
18:42
Errichto Algorithms
Рет қаралды 73 М.
Maximal Square - Top Down Memoization - Leetcode 221
19:50
NeetCode
Рет қаралды 62 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 623 М.
Insert Delete GetRandom O(1) - Leetcode 380 - Python
13:27
NeetCode
Рет қаралды 41 М.
Split Array Largest Sum - Leetcode 410 - Python
16:51
NeetCode
Рет қаралды 76 М.
Cheapest gaming phone? 🤭 #miniphone #smartphone #iphone #fy
0:19
Pockify™
Рет қаралды 4,2 МЛН
Как бесплатно замутить iphone 15 pro max
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 60 М.
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 58 МЛН
Сколько реально стоит ПК Величайшего?
0:37
Что не так с раскладушками? #samsung #fold
0:42
Не шарю!
Рет қаралды 210 М.
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 6 МЛН