Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add subarray sum equals k algorithm#949

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MNnazrul wants to merge1 commit intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromMNnazrul:feat/subarray-sum-equals-k

Conversation

@MNnazrul
Copy link

Description

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

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 ifprefix_sum - k exists in our map, which indicates a subarray with sumk 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 ofrust nightly.
  • I rancargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I rancargo fmt just before my last commit.
  • I rancargo test just before my last commit and all tests passed.
  • I added my algorithm to the correspondingmod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm toDIRECTORY.md with the correct link.
  • I checkedCONTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.44%. Comparing base (21f5615) to head (5ef7b3d).

Additional details and impacted files
@@            Coverage Diff             @@##           master     #949      +/-   ##==========================================+ Coverage   95.39%   95.44%   +0.05%==========================================  Files         332      333       +1       Lines       21496    21532      +36     ==========================================+ Hits        20506    20552      +46+ Misses        990      980      -10

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@imp2002imp2002Awaiting requested review from imp2002imp2002 is a code owner

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@MNnazrul@codecov-commenter

[8]ページ先頭

©2009-2025 Movatter.jp