Тёмный

Range Sum Query Immutable - Leetcode 303 - Python 

NeetCodeIO
Подписаться 176 тыс.
Просмотров 16 тыс.
50% 1

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 12   
@CodingWithCesar
@CodingWithCesar Год назад
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 10 месяцев назад
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 Месяц назад
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).
@sanooosai
@sanooosai 6 месяцев назад
thank you
@flatmapper
@flatmapper Год назад
Amazing!
@MianyunNi
@MianyunNi Год назад
what if left = 0, right = 0; -2 + (-2)
@mehedihassan-pf6yh
@mehedihassan-pf6yh 4 месяца назад
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
Сказала дочке НЕТ!
00:24
Просмотров 1,1 млн
Mark Rober vs Dude Perfect- Ultimate Robot Battle
19:00
System Design of Payment Gateway
1:44:13
Просмотров 11 тыс.
Range Sum Query 2D - Immutable - Leetcode 304 - Python
13:17
LeetCode was HARD until I Learned these 15 Patterns
13:00
Maximum Distance in Arrays - Leetcode 624 - Python
9:23
Elon's Big Bet On Tesla's Future | Optimus 2
18:07
Просмотров 89 тыс.
Integer to English Words - Leetcode 273 - Python
20:59
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Prefix Sums - Problems, Code in C++ & Python
20:51
Просмотров 49 тыс.