Skip to content

Conversation

@vboursinos
Copy link

Summary

Replaces inefficient O(n) implementations in Single class with O(1) mathematical formulas and adds input validation.

Changes

  • Replace array-based sumRange with arithmetic series formula (O(n) → O(1))
  • Fix maxArray to handle negative numbers correctly (was incorrectly initializing max to 0)
  • Optimize sumModulus using arithmetic series instead of Vector iteration
  • Add comprehensive input validation with appropriate exceptions
  • Improve Javadoc documentation with complexity analysis and examples

Testing

  • Verify sumRange handles edge cases (n=0, n=1, negative n)
  • Confirm maxArray works with arrays containing only negative numbers
  • Test sumModulus with various modulus values including negative
  • Validate exception throwing for invalid inputs

Notes

Breaking change: maxArray now throws IllegalArgumentException for null arrays instead of NullPointerException. sumModulus and sumRange now validate inputs and throw exceptions for invalid values.

```
refactor: improve code quality and implementation

Applied general improvements to enhance code structure, readability, and maintainability based on review feedback.
```
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