Commit 580273e
Improve prefix_sum.py (#12560)
* Update prefix_sum.py
Index Validation for get_sum
Raises ValueError if start or end is out of range or start > end.
Handles cases where the array is empty.
✅ Empty Array Support
If an empty array is passed, get_sum raises an appropriate error instead of failing unexpectedly.
✅ Optimized contains_sum Initialization
Initializes sums with {0} for efficient subarray sum checking.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update prefix_sum.py
* Update prefix_sum.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update prefix_sum.py
* Update prefix_sum.py
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxim Smolskiy <[email protected]>1 parent edf7c37 commit 580273e
1 file changed
+19
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
37 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
38 | 56 | | |
39 | 57 | | |
40 | 58 | | |
| |||
0 commit comments