Skip to content

Conversation

Anshusinghh
Copy link

FIXES #1783

What does this PR do?

This PR adds an implementation of the Prefix Sum algorithm (in-place cumulative sum) in JavaScript.

Details

  • Implements prefixSum in Prefix-Sum/BasicPrefixSum.js
    • Validates input (must be numeric array).
    • Throws TypeError on invalid inputs.
    • Modifies the array in-place and returns the same reference.
  • Adds Prefix-Sum/BasicPrefixSum.test.js with unit tests using Vitest.
    • Covers integers, negatives, floats, empty input, and error handling.

Why is this needed?

Prefix sum is a fundamental algorithm widely used in competitive programming and data processing. Having an in-place implementation ensures O(1) extra space.

Checklist

  • Code follows repository style guidelines
  • Added tests with Vitest
  • npm test passes locally
  • No console statements

Thanks for reviewing 🙏 Please let me know if changes are needed.

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.

[FEATURE]: Add Basic Prefix Sum Algorithm with Tests
1 participant