Skip to content

Conversation

@MNnazrul
Copy link
Contributor

Description

This PR adds an implementation of the "Subarray Sum Equals K" algorithm to the general module. The algorithm counts the number of contiguous subarrays that sum to exactly k.

Implementation Method:

  • Uses prefix sum technique with HashMap for O(n) time complexity
  • Space complexity: O(n) for the HashMap
  • Handles edge cases including empty arrays, negative numbers, and zero sums

Algorithm Reference:
This is a classic LeetCode problem (Problem 560). The solution uses the prefix sum approach where we track cumulative sums and check if prefix_sum - k exists in our map, which indicates a subarray with sum k exists.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@MNnazrul MNnazrul requested a review from imp2002 as a code owner November 17, 2025 04:26
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.93%. Comparing base (21f5615) to head (d900c41).
⚠️ Report is 38 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   95.39%   95.93%   +0.54%     
==========================================
  Files         332      362      +30     
  Lines       21496    24649    +3153     
==========================================
+ Hits        20506    23647    +3141     
- Misses        990     1002      +12     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 18, 2025
@zhangzhuang15
Copy link
Contributor

@MNnazrul I like this algorithm because it's simple and intuitive. imp2002 seems to be inactive, you can ask another reviewer for your PR.

@github-actions github-actions bot removed the stale label Dec 25, 2025
@MNnazrul MNnazrul marked this pull request as draft January 8, 2026 05:07
@MNnazrul MNnazrul force-pushed the feat/subarray-sum-equals-k branch from d900c41 to 5ef7b3d Compare January 8, 2026 05:15
@MNnazrul MNnazrul marked this pull request as ready for review January 8, 2026 05:16
@MNnazrul
Copy link
Contributor Author

MNnazrul commented Jan 8, 2026

@zhangzhuang15 I'm unable to change the reviewer from my side.

Screenshot 2026-01-08 at 11 19 28 AM

@zhangzhuang15
Copy link
Contributor

zhangzhuang15 commented Jan 8, 2026 via email

@zhangzhuang15
Copy link
Contributor

Could you please take a look at this PR if you have spare time? @siriak

From my perspective, this PR is simple and friendly for beginning learners.

@zhangzhuang15 I'm unable to change the reviewer from my side.

Screenshot 2026-01-08 at 11 19 28 AM

By the way, imp2002 is not active for review these days, he/she may be really busy. Is there someone else taking own of this code repo and helping imp2002 review PR ? @siriak

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.

Looks good, but don't add more Leetcode problems, we usually don't add them. I think there are no other reviewers now unfortunately.

@siriak siriak merged commit e4c9e6b into TheAlgorithms:master Jan 8, 2026
13 checks passed
@zhangzhuang15
Copy link
Contributor

Looks good, but don't add more Leetcode problems, we usually don't add them. I think there are no other reviewers now unfortunately.

All right., what a pity. Thanks for your response.

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.

4 participants