Skip to content

Commit c697a4c

Browse files
Update prefix_sum.py
1 parent de5705c commit c697a4c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

data_structures/arrays/prefix_sum.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ def get_sum(self, start: int, end: int) -> int:
3030
5
3131
>>> PrefixSum([1,2,3]).get_sum(2, 2)
3232
3
33+
>>> PrefixSum([]).get_sum(0, 0)
34+
Traceback (most recent call last):
35+
...
36+
ValueError: The array is empty.
37+
>>> PrefixSum([1,2,3]).get_sum(-1, 2)
38+
Traceback (most recent call last):
39+
...
40+
ValueError: Invalid range specified.
3341
>>> PrefixSum([1,2,3]).get_sum(2, 3)
3442
Traceback (most recent call last):
3543
...
36-
IndexError: list index out of range
44+
ValueError: Invalid range specified.
45+
>>> PrefixSum([1,2,3]).get_sum(2, 1)
46+
Traceback (most recent call last):
47+
...
48+
ValueError: Invalid range specified.
3749
"""
3850
if not self.prefix_sum:
3951
raise ValueError("The array is empty.")

0 commit comments

Comments
 (0)