Prefix Sum Algorithm and its applications

preview_player
Показать описание
This video will explain the Prefix sum algorithm and explain its application and how we can use this algorithm to solve most of the array interview questions asked in major product based companies like Amazon, Microsoft, Flipkart, Adobe, Uber etc.
This prefix sum technique can be used to solve multiple questions and we have discussed them all in this video along with their code.
1) Equilibrium index in an array
2) Sum array with given sum
3) Sub array with zero sum
3) Subarray with equal no of 1s and 0s
4) Longest subarray with equal no of 0s and 1s.
5) Longest span in 2 binary array with equal no of 0s and 1s.

In addition on that this technique can be used to solve multiple other questions and variations.
So it is very important to know this technique before going for interview.

If you like the video, consider subscribing to the channel for instant updates.

Follow me on social media:
Рекомендации по теме
Комментарии
Автор

Correction in the code:
rightSum will be equal to TotalSum - leftSum - arr[i]

UBlog
Автор

How is the right sum equal to totalSum-arr(i) . I think it should be total-(leftsum+arr(i))

shubh
Автор

For the last question can we solve without subtracting the two arrays?
Like if you are at [i....j] if sum of that subarray is 0 in both the arrays then it is span right?

charan
Автор

1 -1 1 0 1 -1 0 in last example why isn't size is 6 as from index 1 to 6 total sum is 0

vishaljha
Автор

Last one is super i did all Q but was stuck with last

yatri
welcome to shbcf.ru