Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
Vložit
- čas přidán 3. 06. 2024
- Problem Link: bit.ly/3QhMl6j
Notes/C++/Java/Python codes: takeuforward.org/data-structu...
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
Time Stamp
0:00 - Introduction to course
0:41 - Problem Statement
2:13 - Brute Force Solution
6:12 - Better Solution
7:40 - Optimal (Kadane's Algorithm)
13:18 - Code
15:29 - Time Complexity
15:40 - Follow up question
19:37 - Outro
Please watch our new video on the same topic: czcams.com/video/AHZpyENo7k4/video.html
13:56 "Do not carry any negatives into your future" - Striver
Even thought the context was different, it can be applied in our real life❤
Always ready for Dsa ✅
Haan Bhai
Couple of years back, I had watched the best video on CZcams(in terms of views) on Kadanes and still it was not very clear to me. And this video is so so better than the other video. Top level walkthrough.
P.S: I am not comparing. Else I would have told which video was that which I watched earlier :)
Let's march ahead, and create an unmatchable DSA course! ❤
Use the problem links in the description.
bro in case of printing we must have keep track of only last index, think of it,
bcz if after getting maxsum and startind and endind of subarray , if we further get the sum to be negative and then we put sum=0 and startindex to that index and think if we dont get any subarray that have sum greater than previous one, then we lost our startind and endind of main subarray ,then this will give wrong answer
so correct solution for it will be keep only track of endind, so next time when we get higher sum then only change it. and after getting maxsum we can easily get our subarray by using last ind, by going on left side of ind and rightside of ind
weird how this explanation of kadans algo is so simple compared to other yt videos. short algo short code. superb
Nothing can describe how thankful we're to you for such amazing content.. . God Bless you Striver.. Hope you achieve everything you want ❤️❤️
Love your explanation of progression of solutions and code walk through. Please keep making precise and amazing content like this. It really helps to stay motivated with solving problems because when I'm stuck, the logic in your vids is explained very clearly. Thanks a lot!!
Complete concept clarity in 20 mins. Amazing ✅✅✅✅
i saw many videos but not able to understad.... this video gave me complete understading..Thanks bro
bro i really love your explanation ;how ever i explane doudtes to my frnds you explaining in same manner ❤
Your way of explanation is really outstanding🔥🔥🙌thanks lot and more!!!!
"Understood " superb intuition of algorithm !! awsome explanation i request everyone whoever watching strivers vedeos do like and comment!!!
i was very keen about learning DSA and your sheet and your explanation has boosted this thank you strive bhaiya
Understood! Super excellent explanation as always, thank you very very much for your effort!!
in love with kadane algorithm...all thanks to you bhaiya
Printing the subarrays part is something i learn this time tysm understood:)
Thank You so much for made this crystal clear understanding about this problem.
12:28
very nice explaination. Very helpful walk through that cleared my confusions
Easiest explaination ever👌👌 thanks bhaiya...!!
Im new to programming and this was very helpful ~
BEST Kadane's algo video on the internet!
Understood, Amazing Lecture Sir!
Kadame's Algorithm is now clear. Thankyou Striver ❤
From brute(TC -> O(N^3), SC -> O(1)) to better(TC -> O(N^2), SC -> O(1)) to Optimal(TC -> O(N), SC -> O(1))
you are doing great job striver ❤.. .
understood you are the best teacher. 🙌
Super explanation with so much love 😃
Thank you very much bhaiya for these.
In upcoming videos please add general approach for techniques like sliding window, two pointers etc techniques as the way you give for recursion and dp etc.
Thank you once again bhaiya
Bro really you have good knowledge of DSA...
great concepts , understood everything
Absolutely Amazing ✌️🔥
Time Stamp
0:00 - Introduction to course
0:41 - Problem Statement
2:13 - Brute Force Solution
6:12 - Better Solution
7:40 - Optimal (Kadane's Algorithm)
13:18 - Code
15:29 - Time Complexity
15:40 - Follow up question
19:37 - Outro
There's always something new to learn from striver's videos . Thank You bhai for posting videos without any long gap!!!.
Crystal Clear Understanding !
Understood. Thanks a lot. Please upload more videos Bhaiyaaa.
i am following this course for my dsa preparation , its an amazing course and explanation by bhaiya
just want one thing complete this by end of october ♥♥
have u completed
Understood,Thank striver for this amazing video.
Thanks brother Best Explanation😊
SDE Sheet Day 1 Problem 1 Done!
Understood.. thank you so much bro
Good explanation.
Best explanation everr
Understood!.Thank you.
All videos are very helpful
Amazing!! Keep going bro⚡
done and dusted ! hats off to striver ..
Understood. Thanks a ton 😇
simply , loved it....
understood ,thnx for the video ❤❤❤❤❤❤
Great job👍🏻
UNDERSTOOD SIR🙇♂❤🙏
Understood and thanks for the video
Completely Understood!
Thanks for explanation
thank you very much brother.
Understood. Thank you.
BEST TEACHERRRR EVERR!!!!!!!!!!
Thanks bro, just subbed to the channel
Understood striver! 🔥👍
Amazing experience
mind blowing sir
Thanks so much striver
Incredible 🎉
Thank you 🙏
Understood Boss, it helps !!
The result will never be lesser than zero because one condition is "if(sum>max) max=sum" and initially sum=0 and max=LONG_MIN. hence, max will always be zero if all the values in the array are negative.
It is returning maxi variable so even if it is sum is negative and we make sum zero and then add a negative number to sum it will be lesser than the maxi variable
Understood thanks 🙏
Understood ❤bhaiya❤❤
thank you sir❣
Tired of commenting AMAZING bhaiya ;) !! You're tooooo good :)
Great work
understood brother
Understood Sir.............
Understood bhaiya!
Understand Brother.
UNDERSTOOD SIR
1. is the carryforward and sliding window technique is both are same? 2. can you please tell me the difference between carryforward and sliding window technique? it will be really helpful if you explain me sir.
Thank you Bhaiya
15:05 editing mistake 🫡 but no worries
shit yes, thankfully not a big one
@@takeUforward please make a video on long pressed name
@@takeUforward which tool you are using for white boarding?
loved it!
Amazing ❤
understood everything
thank you sir
understood
understood boss 😎
Can't wait for binary search series
Bro its 2pm night in India, You are doing great Job, consistency 💥
He is in warsaw, which means he uploaded the video between 9:30-10 pm in his time
Yes I could not do it during the morning today. Came back from office and recorded, edited and uploaded 😄
Am hai🤭🤭🤭
@@takeUforward Thats why your content is the best
understood
// first time bro
Understood, thanks :)
Understood✅🔥🔥
at 15:22 you have to add this code in for loop . if(maxi
Understood Sir!
understood 😇
Thanks bhaiya 💖💖
Striver is Love yr❤
Understood!!❤
kadane's algorithm c++ code: there was error in editing so i wrote the code this might help beginners like me :)
#include
using namespace std;
int main()
{
int n = 8;
int arr[n] = {-2, -3, 4, -1, -2, 1, 5, -3};
long long sum = 0, maxi = LONG_MIN;
int start = 0, end = 0;
for (int i = 0; i < 8; i++)
{
if (sum == 0)
{
start = i;
}
sum += arr[i];
if (sum > maxi)
{
maxi = sum;
end = i;
}
if (sum < 0)
{
sum = 0;
}
}
for (int i = start; i
Thanku u
@@vaishalirawat2447 welcome.
bro kindly put video about heap . i seen others videos but i need yours
Understood !!
Thank you!
8:20 "Do not worry" ✨
Understood!