Range Sum Query Immutable - Leetcode 303 - Python

  Рет қаралды 22,865

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 12
@cesarfa-b3t
@cesarfa-b3t Жыл бұрын
A trick I like to use for the prefix array is to subtract left and add nums[left] instead of going one position over so we don't have to worry about boundary check, for example: prefix[right] - prefix[left] + nums[left]
@samcarter8828
@samcarter8828 Жыл бұрын
Nice trick
@gradientO
@gradientO Жыл бұрын
but that requires us to store the nums array. Using prefix array, we dont need that
@tsunami8892
@tsunami8892 Жыл бұрын
also that can be - prefix[right] - (prefix[left - 1] || 0)
@ChrisCox-wv7oo
@ChrisCox-wv7oo Жыл бұрын
prefix[-1] returns the last element in Python
@shavvasatya7131
@shavvasatya7131 Жыл бұрын
Great as usual.
@flatmapper
@flatmapper Жыл бұрын
2:00 Why O(n^2)? O(n^2) is the time complexity of finding pairs. Intuitively the time complexity is greater to find every subarray
@MsPokemonmaster145
@MsPokemonmaster145 6 ай бұрын
He is saying that the number of subarrays is O(n^2) (To be exact, n*(n-1)). You are right tho to find all sums it would take O(n^3).
@flatmapper
@flatmapper Жыл бұрын
Amazing!
@sanooosai
@sanooosai 11 ай бұрын
thank you
@Amisss-t7s
@Amisss-t7s Жыл бұрын
what if left = 0, right = 0; -2 + (-2)
@mehedihassan-pf6yh
@mehedihassan-pf6yh 9 ай бұрын
You wrote left > 0 then but as index , left can be 0 to indicate first index
Middle of the Linked List - Leetcode 876 - Python
4:57
NeetCodeIO
Рет қаралды 31 М.
Range Sum Query 2D - Immutable - Leetcode 304 - Python
13:17
NeetCode
Рет қаралды 45 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
Вопрос Ребром - Джиган
43:52
Gazgolder
Рет қаралды 3,8 МЛН
Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python
15:19
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 303 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 327 М.
Tuple with Same Product - Leetcode 1726 - Python
19:27
NeetCodeIO
Рет қаралды 7 М.
Subarray Sums Divisible by K - Leetcode 974 - Python
16:41
NeetCodeIO
Рет қаралды 21 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 804 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 683 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 248 М.
Prefix Sum Array and Range Sum Queries
7:30
Profound Academy
Рет қаралды 9 М.