Skip to content

Implement Maximum Sum of Non-Adjacent Elements #5544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Oct 10, 2024
Merged

Implement Maximum Sum of Non-Adjacent Elements #5544

merged 26 commits into from
Oct 10, 2024

Conversation

Guhapriya01
Copy link
Contributor

@Guhapriya01 Guhapriya01 commented Oct 3, 2024

This PR adds an algorithm to find the maximum sum of non-adjacent elements in an array. The implementation includes two approaches:

Dynamic Programming with O(n) Space Complexity:

  • Utilizes a dynamic programming array to store the maximum sum at each index.
  • Time Complexity: O(n)
  • Space Complexity: O(n)

Optimized Space Complexity Approach:

  • Uses two variables to track the maximum sums, reducing space complexity to O(1).
  • Time Complexity: O(n)
  • Space Complexity: O(1)
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Related Issues : Issue #5510

@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.21%. Comparing base (c152c38) to head (eeb2936).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5544      +/-   ##
============================================
+ Coverage     60.15%   60.21%   +0.05%     
- Complexity     3868     3876       +8     
============================================
  Files           562      563       +1     
  Lines         16009    16035      +26     
  Branches       3069     3073       +4     
============================================
+ Hits           9631     9655      +24     
- Misses         5973     5974       +1     
- Partials        405      406       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Guhapriya01 Guhapriya01 closed this Oct 3, 2024
@Guhapriya01 Guhapriya01 reopened this Oct 3, 2024
@Guhapriya01 Guhapriya01 marked this pull request as ready for review October 3, 2024 11:37
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

@Guhapriya01
Copy link
Contributor Author

Hi @siriak , I've addressed your feedback by fixing the Clang PR check and adding JUnit tests for the MaximumSumOfNonAdjacentElements class.

@Guhapriya01 Guhapriya01 requested a review from siriak October 6, 2024 06:09
@Guhapriya01 Guhapriya01 requested a review from siriak October 8, 2024 06:21
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Please check why build PR check is failing

@Guhapriya01 Guhapriya01 requested a review from siriak October 9, 2024 05:53
@siriak siriak merged commit 44b0fc9 into TheAlgorithms:master Oct 10, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants