Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
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]
Nice trick
but that requires us to store the nums array. Using prefix array, we dont need that
also that can be - prefix[right] - (prefix[left - 1] || 0)
prefix[-1] returns the last element in Python
Great as usual.
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
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).
thank you
Amazing!
what if left = 0, right = 0; -2 + (-2)
You wrote left > 0 then but as index , left can be 0 to indicate first index
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]
Nice trick
but that requires us to store the nums array. Using prefix array, we dont need that
also that can be - prefix[right] - (prefix[left - 1] || 0)
prefix[-1] returns the last element in Python
Great as usual.
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
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).
thank you
Amazing!
what if left = 0, right = 0; -2 + (-2)
You wrote left > 0 then but as index , left can be 0 to indicate first index