Skip to content

Conversation

ydvmudit07
Copy link
Contributor

Closes #143

This pull request implements the maximum subarray sum algorithm, also known as Kadane's algorithm.

Changes:

  • Added max_subarray_sum() function
  • Initializes variables to track maximum sum ending at current position and maximum seen so far
  • Iterates through array, calculating max ending at current position
  • Compares with max seen so far and updates
  • Returns overall maximum subarray sum

This algorithm efficiently finds the contiguous subarray with the largest sum within a given array. I have added tests to validate the implementation with different input cases. @himanshu-03 , please review the code changes and let me know if anything needs to be updated or improved. I'm happy to make revisions to ensure this algorithm is accurately and efficiently implemented.

Looking forward to getting this useful algorithm merged to the codebase under the hacktoberfest tag!


image

Copy link
Owner

@himanshu-03 himanshu-03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that kadanes algorithm should not be placed in algorithm directory. Take a look around the repo and see if it can fit around already defined directories.

@ydvmudit07
Copy link
Contributor Author

Sure I'll do it, thanks for letting me know.

@ydvmudit07
Copy link
Contributor Author

ydvmudit07 commented Oct 26, 2023

@himanshu-03 , based on the existing folder structure of the Python DSA repository, I just added the Kadane's algorithm implementation in the "Math" folder.

The Kadane's algorithm involves finding the maximum subarray sum within an array using mathematical logic and comparisons. Since it is more of a mathematical algorithm rather than a specific data structure or technique, the "Math" folder seems like the best fit.

Let me know if you need any other specific folder name recommendations or have additional context to consider
Kindly review and merge it under the tag "hacktoberfest"!

Copy link
Owner

@himanshu-03 himanshu-03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@himanshu-03
Copy link
Owner

Great job!
Thank you for contributing. Do give this repository a star if you feel like ✨️

@himanshu-03 himanshu-03 merged commit da2887a into himanshu-03:main Oct 26, 2023
@himanshu-03 himanshu-03 added the hacktoberfest-accepted The pull request is overall hacktoberfest acceptable label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted The pull request is overall hacktoberfest acceptable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add: Maximum Subarray Sum (Kadane's Algorithm)
2 participants