Skip to content

Commit 944c5f9

Browse files
authored
Update kadane_algorithm.py
Removing the usage if typing package and using inbuilt list instead.
1 parent ec206e1 commit 944c5f9

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

dynamic_programming/kadane_algorithm.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@
77
https://en.wikipedia.org/wiki/Maximum_subarray_problem
88
"""
99

10-
from typing import List, Tuple
1110

12-
13-
def kadane(arr: List[int]) -> Tuple[int, List[int]]:
11+
def kadane(arr):
1412
"""
1513
Returns the maximum sum of a contiguous subarray and the subarray itself.
1614
1715
Parameters
1816
----------
19-
arr : List[int]
17+
arr : list
2018
List of integers (can be positive, negative, or zero).
2119
2220
Returns
2321
-------
24-
Tuple[int, List[int]]
22+
tuple
2523
Maximum subarray sum and the corresponding subarray.
2624
2725
Examples
2826
--------
2927
>>> kadane([-2,1,-3,4,-1,2,1,-5,4])
3028
(6, [4, -1, 2, 1])
31-
29+
3230
>>> kadane([1,2,3,4])
3331
(10, [1, 2, 3, 4])
34-
32+
3533
>>> kadane([-1,-2,-3])
3634
(-1, [-1])
3735
"""
@@ -53,11 +51,10 @@ def kadane(arr: List[int]) -> Tuple[int, List[int]]:
5351
start = s
5452
end = i
5553

56-
return max_global, arr[start : end + 1]
54+
return max_global, arr[start:end+1]
5755

5856

5957
# Doctest runner
6058
if __name__ == "__main__":
6159
import doctest
62-
6360
doctest.testmod()

0 commit comments

Comments
 (0)