Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing

Sdílet
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

Komentáře • 342

  • @takeUforward
    @takeUforward  Před 9 měsíci +10

    Please watch our new video on the same topic: czcams.com/video/AHZpyENo7k4/video.html

  • @lavanyam3224
    @lavanyam3224 Před 3 měsíci +27

    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❤

  • @rishabh1S
    @rishabh1S Před rokem +76

    Always ready for Dsa ✅

  • @chethanprabhu4475
    @chethanprabhu4475 Před rokem +71

    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 :)

  • @takeUforward
    @takeUforward  Před rokem +77

    Let's march ahead, and create an unmatchable DSA course! ❤
    Use the problem links in the description.

    • @princejatav8456
      @princejatav8456 Před 9 měsíci +1

      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

  • @rpanda_old
    @rpanda_old Před rokem +9

    weird how this explanation of kadans algo is so simple compared to other yt videos. short algo short code. superb

  • @3egang_
    @3egang_ Před rokem +21

    Nothing can describe how thankful we're to you for such amazing content.. . God Bless you Striver.. Hope you achieve everything you want ❤️❤️

  • @user-cj3zr7pu7t
    @user-cj3zr7pu7t Před rokem

    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!!

  • @arnavjain762
    @arnavjain762 Před 3 měsíci

    Complete concept clarity in 20 mins. Amazing ✅✅✅✅

  • @yelururao1
    @yelururao1 Před 7 měsíci

    i saw many videos but not able to understad.... this video gave me complete understading..Thanks bro

  • @user-mq4fu9yh4t
    @user-mq4fu9yh4t Před rokem +1

    bro i really love your explanation ;how ever i explane doudtes to my frnds you explaining in same manner ❤

  • @archanaverma8771
    @archanaverma8771 Před 10 měsíci

    Your way of explanation is really outstanding🔥🔥🙌thanks lot and more!!!!

  • @bendivanitha7211
    @bendivanitha7211 Před 10 měsíci +1

    "Understood " superb intuition of algorithm !! awsome explanation i request everyone whoever watching strivers vedeos do like and comment!!!

  • @SurajGupta-gc9tz
    @SurajGupta-gc9tz Před 6 měsíci

    i was very keen about learning DSA and your sheet and your explanation has boosted this thank you strive bhaiya

  • @cinime
    @cinime Před rokem

    Understood! Super excellent explanation as always, thank you very very much for your effort!!

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu Před 2 měsíci

    in love with kadane algorithm...all thanks to you bhaiya

  • @Raj10185
    @Raj10185 Před rokem +2

    Printing the subarrays part is something i learn this time tysm understood:)

  • @manjamalaimm6178
    @manjamalaimm6178 Před 3 měsíci

    Thank You so much for made this crystal clear understanding about this problem.

  • @radhakishoriiiiiiiiiii7348
    @radhakishoriiiiiiiiiii7348 Před 6 měsíci

    12:28
    very nice explaination. Very helpful walk through that cleared my confusions

  • @factfortune2160
    @factfortune2160 Před 4 měsíci

    Easiest explaination ever👌👌 thanks bhaiya...!!

  • @allegragarland9156
    @allegragarland9156 Před 5 měsíci

    Im new to programming and this was very helpful ~

  • @vaishnaviganseh2884
    @vaishnaviganseh2884 Před 11 měsíci

    BEST Kadane's algo video on the internet!

  • @VarunKaushal-zx9zq
    @VarunKaushal-zx9zq Před 11 měsíci +1

    Understood, Amazing Lecture Sir!

  • @Manishgupta200
    @Manishgupta200 Před rokem +4

    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))

  • @iitmotivationwithrahullson5930

    you are doing great job striver ❤.. .

  • @sparshverma4030
    @sparshverma4030 Před rokem

    understood you are the best teacher. 🙌

  • @PriyanshuKumar-zd1lq
    @PriyanshuKumar-zd1lq Před 10 měsíci

    Super explanation with so much love 😃

  • @piaknow3881
    @piaknow3881 Před rokem +1

    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

  • @ArunKumar-zp8cp
    @ArunKumar-zp8cp Před rokem

    Bro really you have good knowledge of DSA...

  • @prabalsharma3007
    @prabalsharma3007 Před 6 měsíci

    great concepts , understood everything

  • @swagnikdhar6010
    @swagnikdhar6010 Před rokem +1

    Absolutely Amazing ✌️🔥

  • @manipandit18
    @manipandit18 Před rokem +29

    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!!!.

  • @syedFAHIM-el1wr
    @syedFAHIM-el1wr Před rokem

    Crystal Clear Understanding !

  • @samuelfrank1369
    @samuelfrank1369 Před 7 měsíci

    Understood. Thanks a lot. Please upload more videos Bhaiyaaa.

  • @shivamsingh-we7ek
    @shivamsingh-we7ek Před 10 měsíci +2

    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 ♥♥

  • @hareshnayak7302
    @hareshnayak7302 Před 2 měsíci

    Understood,Thank striver for this amazing video.

  • @AmanPandey-bd1sj
    @AmanPandey-bd1sj Před 7 měsíci

    Thanks brother Best Explanation😊

  • @suyashshinde2971
    @suyashshinde2971 Před rokem +2

    SDE Sheet Day 1 Problem 1 Done!

  • @tamilmukbang3789
    @tamilmukbang3789 Před měsícem

    Understood.. thank you so much bro

  • @kannan10308
    @kannan10308 Před 6 dny

    Good explanation.

  • @tulsilukhi1182
    @tulsilukhi1182 Před 20 dny

    Best explanation everr

  • @user-gq6sq8zk8s
    @user-gq6sq8zk8s Před 4 měsíci +1

    Understood!.Thank you.

  • @AyushSharma-ye1xz
    @AyushSharma-ye1xz Před rokem

    All videos are very helpful

  • @Ashishvatsav
    @Ashishvatsav Před 3 měsíci

    Amazing!! Keep going bro⚡

  • @hunter-js8hy
    @hunter-js8hy Před 4 dny

    done and dusted ! hats off to striver ..

  • @prateekmahajan5490
    @prateekmahajan5490 Před měsícem

    Understood. Thanks a ton 😇

  • @ITSuyashTiwari
    @ITSuyashTiwari Před 6 měsíci

    simply , loved it....

  • @AniketKumar-hf2bo
    @AniketKumar-hf2bo Před 4 měsíci

    understood ,thnx for the video ❤❤❤❤❤❤

  • @vaishalidhokchawle4384
    @vaishalidhokchawle4384 Před měsícem

    Great job👍🏻

  • @_hulk748
    @_hulk748 Před rokem

    UNDERSTOOD SIR🙇‍♂❤🙏

  • @devipavanlankalapalli7587
    @devipavanlankalapalli7587 Před 5 měsíci

    Understood and thanks for the video

  • @EC20022ELAKKIYAC
    @EC20022ELAKKIYAC Před 4 měsíci

    Completely Understood!

  • @stutidutta3922
    @stutidutta3922 Před 11 měsíci

    Thanks for explanation

  • @mr_weird3680
    @mr_weird3680 Před 2 měsíci

    thank you very much brother.

  • @DevashishJose
    @DevashishJose Před rokem

    Understood. Thank you.

  • @tasneemayham974
    @tasneemayham974 Před 8 měsíci

    BEST TEACHERRRR EVERR!!!!!!!!!!

  • @francksgenlecroyant
    @francksgenlecroyant Před 8 měsíci

    Thanks bro, just subbed to the channel

  • @SriSarthak257
    @SriSarthak257 Před měsícem

    Understood striver! 🔥👍

  • @JitendraKumar-ll4lz
    @JitendraKumar-ll4lz Před rokem

    Amazing experience

  • @banothutharun2743
    @banothutharun2743 Před 3 měsíci

    mind blowing sir

  • @adebisisheriff159
    @adebisisheriff159 Před 6 měsíci

    Thanks so much striver

  • @dasaridharani6529
    @dasaridharani6529 Před 9 měsíci

    Incredible 🎉

  • @UECAshutoshKumar
    @UECAshutoshKumar Před 2 měsíci +1

    Thank you 🙏

  • @rajindersharma4
    @rajindersharma4 Před 5 měsíci

    Understood Boss, it helps !!

  • @sahadevbhaganagare4761
    @sahadevbhaganagare4761 Před 5 měsíci +4

    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.

    • @user-zr3eu2oo7s
      @user-zr3eu2oo7s Před měsícem

      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

  • @reddygopichand2002
    @reddygopichand2002 Před 7 měsíci

    Understood thanks 🙏

  • @YerramArun
    @YerramArun Před rokem

    Understood ❤bhaiya❤❤

  • @creativeprojects217
    @creativeprojects217 Před 4 měsíci

    thank you sir❣

  • @aryanmaniyar3475
    @aryanmaniyar3475 Před 9 měsíci

    Tired of commenting AMAZING bhaiya ;) !! You're tooooo good :)

  • @akofficialss
    @akofficialss Před rokem

    Great work

  • @user-sg1jx3ic4q
    @user-sg1jx3ic4q Před měsícem

    understood brother

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 Před 2 měsíci

    Understood Sir.............

  • @infernogamer52
    @infernogamer52 Před 11 měsíci

    Understood bhaiya!

  • @forstudycode6146
    @forstudycode6146 Před 9 měsíci

    Understand Brother.

  • @user-dv1ts9db8i
    @user-dv1ts9db8i Před 2 měsíci

    UNDERSTOOD SIR

  • @vinethasuresh3488
    @vinethasuresh3488 Před rokem +4

    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.

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l Před 4 měsíci

    Thank you Bhaiya

  • @user-xr2bu9lw8c
    @user-xr2bu9lw8c Před rokem +6

    15:05 editing mistake 🫡 but no worries

    • @takeUforward
      @takeUforward  Před rokem +2

      shit yes, thankfully not a big one

    • @vish-sw9dc
      @vish-sw9dc Před rokem

      ​@@takeUforward please make a video on long pressed name

    • @Poojithaalam
      @Poojithaalam Před 3 měsíci

      @@takeUforward which tool you are using for white boarding?

  • @arman2793
    @arman2793 Před 5 měsíci

    loved it!

  • @PankajSingh-pb4vs
    @PankajSingh-pb4vs Před 3 měsíci

    Amazing ❤

  • @kingbadshah452
    @kingbadshah452 Před 4 měsíci

    understood everything

  • @student_03
    @student_03 Před 11 měsíci

    thank you sir
    understood

  • @ArvindSingh-wj7vy
    @ArvindSingh-wj7vy Před 2 měsíci

    understood boss 😎

  • @ashishdhal4614
    @ashishdhal4614 Před rokem

    Can't wait for binary search series

  • @yugamsaini8761
    @yugamsaini8761 Před rokem +9

    Bro its 2pm night in India, You are doing great Job, consistency 💥

    • @rohitprasad5708
      @rohitprasad5708 Před rokem +1

      He is in warsaw, which means he uploaded the video between 9:30-10 pm in his time

    • @takeUforward
      @takeUforward  Před rokem +19

      Yes I could not do it during the morning today. Came back from office and recorded, edited and uploaded 😄

    • @uncannyroaches5933
      @uncannyroaches5933 Před rokem

      Am hai🤭🤭🤭

    • @rohitprasad5708
      @rohitprasad5708 Před rokem +1

      @@takeUforward Thats why your content is the best

  • @navkaransinghbrar4380

    understood
    // first time bro

  • @itsabhinav04
    @itsabhinav04 Před rokem

    Understood, thanks :)

  • @YourCodeVerse
    @YourCodeVerse Před 7 měsíci

    Understood✅🔥🔥

  • @tarunsingh4413
    @tarunsingh4413 Před 4 měsíci

    at 15:22 you have to add this code in for loop . if(maxi

  • @parshchoradia9909
    @parshchoradia9909 Před rokem

    Understood Sir!

  • @culeforever5408
    @culeforever5408 Před 7 měsíci +1

    understood 😇

  • @programmingsoul4269
    @programmingsoul4269 Před 10 měsíci

    Thanks bhaiya 💖💖

  • @nishant1456
    @nishant1456 Před rokem +1

    Striver is Love yr❤

  • @harshas5462
    @harshas5462 Před 7 měsíci

    Understood!!❤

  • @amarsharma8582
    @amarsharma8582 Před rokem +15

    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

  • @rohithdon2621
    @rohithdon2621 Před rokem

    bro kindly put video about heap . i seen others videos but i need yours

  • @babuprasadr4205
    @babuprasadr4205 Před 3 dny

    Understood !!

  • @naveenkumarchukka4280

    Thank you!

  • @aslamcodes
    @aslamcodes Před 8 měsíci

    8:20 "Do not worry" ✨

  • @mrnobody4365
    @mrnobody4365 Před 18 dny

    Understood!