2D Prefix Sum and Submatrix Sum Queries

  Рет қаралды 4,082

Profound Academy

Profound Academy

Күн бұрын

A 2-dimensional prefix sum is a powerful algorithmic technique used in computer science and mathematics to preprocess a given 2D grid or matrix, enabling efficient querying of summed values over rectangular subregions. In essence, it is an extension of the 1-dimensional prefix sum to two dimensions. This method involves constructing an auxiliary matrix of the same dimensions as the original, where each cell (i, j) contains the sum of all elements in the rectangular region formed by the top-left corner (0, 0) and the current position (i, j). Once this preprocessing is complete, the sum of any rectangular subregion can be calculated with only four array lookups and three arithmetic operations, significantly reducing the time complexity of repeated queries.
💻 Practice: profound.academy/algorithms-d...
📚 Full DSA Course: profound.academy/algorithms-d...
🎓 Teach with Profound Academy: profound.academy/teach
profound.academy
/ profound.academy.inc
/ profound.academy.inc
/ profound-academy-inc
Chapters:
0:00 2D Prefix Sum and Submatrix Sum Queries Problem Statement
0:19 Example Matrix
0:39 2D Prefix Sum
0:57 Submatrix Sum Query
2:05 Trick of Padding the Array With Zeros
2:29 2D Prefix Sum Array Calculation
3:26 Hands-on Practice on Profound Academy
3:37 Algorithm in Action
4:41 Time and Memory Complexity
#PrefixSum #Algorithm #DataStructures #2dPrefixSum #Algorithms #ProblemSolving #AlgorithmicInterview #InterviewPreparation #DataStructuresInterview #InterviewQuestions #TechInterview #TechInterviews #DSA #GoogleInterview #FAANG #Algorithms

Пікірлер: 7
@karenmirakyan1610
@karenmirakyan1610 Жыл бұрын
Well explained, waiting for other videos 👍
@user-vz7wd9fh3c
@user-vz7wd9fh3c 2 ай бұрын
Perfect illustration
@helloomkar
@helloomkar Ай бұрын
Perfect explanation and viz needed for this concept. Glad i came to your video🎉🎉
@HaykTarkhanyan
@HaykTarkhanyan Жыл бұрын
Awesome, keep it up
@florinseiler3764
@florinseiler3764 Жыл бұрын
Awesome video! Helped a lot
@DK-ox7ze
@DK-ox7ze Жыл бұрын
What's the logic behind calculating prefix sum for each cell? What's the intuition behind the formula you used?
@shashankbj3804
@shashankbj3804 6 ай бұрын
You should watch it again its in the video..
Sliding Window Technique
6:18
Profound Academy
Рет қаралды 7 М.
Prefix Sum Array and Range Sum Queries
7:30
Profound Academy
Рет қаралды 3,1 М.
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 42 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 59 МЛН
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 13 МЛН
Best father #shorts by Secret Vlog
00:18
Secret Vlog
Рет қаралды 22 МЛН
Maximum Sum Rectangular Submatrix in Matrix dynamic programming/2D kadane
13:54
Tushar Roy - Coding Made Simple
Рет қаралды 202 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
Sieve of Eratosthenes - Find All Prime Numbers up to N
7:41
Profound Academy
Рет қаралды 469
Range Sum Query 2D - Immutable - Leetcode 304 - Python
13:17
NeetCode
Рет қаралды 36 М.
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
take U forward
Рет қаралды 240 М.
How I Got Good at Coding Interviews
6:29
NeetCode
Рет қаралды 1,6 МЛН
Why Number Theory is Hard (Audio Fix in Description)
6:05
Art Kalb
Рет қаралды 53 М.
Prefix Sums - Problems, Code in C++ & Python
20:51
Errichto Algorithms
Рет қаралды 44 М.
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 42 МЛН