Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 097e85a

Browse files
committedOct 2, 2024·
added doctest
1 parent 07b6e6c commit 097e85a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎data_structures/arrays/sliding_window.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def sum(array:list ,size:int ,k:int) -> int:
2727
Returns:
2828
int : sum of the minimum and maximum elements of all sub-arrays of size-k
2929
"""
30-
30+
"""
31+
Examples:
32+
>>> sum([2, 5, -1, 7, -3, -1, -2], 7 ,4)
33+
18
34+
"""
3135
# create first window of size k
3236
start ,end = 0 ,k-1
3337
result = 0
@@ -43,7 +47,5 @@ def sum(array:list ,size:int ,k:int) -> int:
4347
return result
4448

4549
if __name__ == '__main__':
46-
array = [2, 5, -1, 7, -3, -1, -2]
47-
K = 4
48-
size = 7
49-
print(sum(array,size,K))
50+
import doctest
51+
doctest.testmod()

0 commit comments

Comments
 (0)
Please sign in to comment.