Maximum Sub-Array Sum (LeetCode 53) | Kadane's Algorithm | Study Algorithms

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 27. 07. 2024
  • Maximum sub-array is a programming challenge on LeetCode. You are provided with an array of integers. These elements could be all positive, all negative or a combination of both. A sub-array is a smaller array formed using the elements of the original array. The condition for this problem is that the elements of the sub-array should be contiguous. Out of all the contiguous sub-arrays possible we need to find the maximum sum that can be formed. Watch the video to understand the problem in a simplified manner. I then work along with you to solve it first using a Brute Force approach, and then an efficient approach. All along with visuals and explanations.
    00:00 - Intro
    00:29 - Problem Statement and Test Case
    02:15 - Brute Force Method
    04:15 - Optimized Solution
    07:10 - Dry-run of code
    📚 Links I talk about in the video:
    Actual problem on LeetCode: leetcode.com/problems/maximum...
    Code on Github: github.com/nikoo28/java-solut...
    Test cases on GitHub: github.com/nikoo28/java-solut...
    📘 A text based explanation is available at: studyalgorithms.com/array/max...
    Kadane's algorithm: en.wikipedia.org/wiki/Maximum...
    To see more videos like this, you can show your support on www.buymeacoffee.com/studyalg...
    đŸ’» Get Social đŸ’»
    Follow on Facebook at: / studyalgos
    Follow on Twitter at: / studyalgorithms
    Follow on Tumblr at: / studyalgos
    Subscribe to RSS feeds: studyalgorithms.com/feed/
    #leetcode #programming #interview

Komentáƙe • 21

  • @omsudhamsh.h
    @omsudhamsh.h Pƙed 2 měsĂ­ci

    The explanation is so good!
    Thanks brother

  • @srin42
    @srin42 Pƙed 2 lety +5

    Hey, Your awesome, Please do more videos on frequently asked questions .Please do more content you will get million subscriber's because your content and white board, practical code walk is awesome. Once content grows more you will start to see many subscribers because we like your explanation. I just told my whats app group friends and they will subscribe soon.

    • @nikoo28
      @nikoo28  Pƙed 2 lety +5

      Thanks for all the support. To add more and more questions I do take requests. You can dm me or just tell me the question in comments.
      I too wish I could make more frequent videos
but don’t want to do any compromises on the quality. Thanks for sharing the video to your friends.
      This really motivates me.

  • @anonlegion8331
    @anonlegion8331 Pƙed 7 měsĂ­ci +1

    Thank you so much. Your videos are really helpful for me in understanding how to approach these problems.

    • @nikoo28
      @nikoo28  Pƙed 7 měsĂ­ci +1

      You're very welcome!

  • @naveenkumar-im6rh
    @naveenkumar-im6rh Pƙed 4 měsĂ­ci

    Thank you so much sir

  • @unemployedcse3514
    @unemployedcse3514 Pƙed 2 měsĂ­ci

    awesome brother❀

  • @subee128
    @subee128 Pƙed 7 měsĂ­ci +3

    Thanks

  • @savitrik3596
    @savitrik3596 Pƙed měsĂ­cem

    Thank you😃

  • @kalyanamvenumadhav2245
    @kalyanamvenumadhav2245 Pƙed rokem +3

    why are we taking values from 3 (4th index) on wards (right to left) why not we start with 2nd and 3rd indices is there any reason for that

  • @kishanraiyani7048
    @kishanraiyani7048 Pƙed 29 dny

    Thanks brother.
    The explanation is great and your dynamic programming playlist is awesome.
    One question:
    What if we are asked to find that subarray start and end indexes as well ?
    How we will find ?

    • @nikoo28
      @nikoo28  Pƙed 26 dny

      you will need to keep a track of those indexes. try to write a pseudocode for it

  • @Itsallrelative1
    @Itsallrelative1 Pƙed 4 lety +4

    why is the sum of the lone element -2, 2? at 3.27

    • @nikoo28
      @nikoo28  Pƙed 4 lety

      I misspoke over there. The sum of the alone element would be just '-2'

  • @topricano9964
    @topricano9964 Pƙed 23 dny

    I'm afraid of this problem because of it's name "Kadane's Algorithm" ... After ur video I went to GeeksForGeeks and solve this also solved it in Leetcode...
    Thankyou so much!!... I thought DSA is very hard for me..But ur explanations made it very easyy!!

  • @mixupthings
    @mixupthings Pƙed 2 lety +1

    did not get it pls explain

    • @nikoo28
      @nikoo28  Pƙed 2 lety +1

      Which part are you having trouble in understanding? I can help you out.

  • @nikitadeoree
    @nikitadeoree Pƙed 6 měsĂ­ci

    hey sir why i=1 we get a -7

    • @nikoo28
      @nikoo28  Pƙed 5 měsĂ­ci

      please point me to the timestamp you are having a problem with

  • @Nayak_20__
    @Nayak_20__ Pƙed 6 měsĂ­ci +1

    Hello sir, where i can find this problem in leet code

    • @nikoo28
      @nikoo28  Pƙed 6 měsĂ­ci

      The link is always available in the description.