We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5971ffe commit 96fcb53Copy full SHA for 96fcb53
1 file changed
data_structures/arrays/maximum_subarray_sum.py
@@ -1,16 +1,27 @@
1
-def maxSubarraySum(arr):
+def maxSubarraySum(arr: list[int) -> int:
2
+ """
3
+ Find the maximum sum of a subarray.
4
+
5
+ Args:
6
+ arr: array of numbers.
7
8
+ Returns:
9
+ Maximum sum possible in a subarray
10
11
ans = arr[0]
12
13
for i in range(len(arr)):
- currentSum = 0
14
+ current_sum = 0
15
16
for j in range(i, len(arr)):
- currentSum = currentSum + arr[j]
- ans = max(ans, currentSum)
17
+ current_sum = current_sum + arr[j]
18
+ ans = max(ans, current_sum)
19
20
return ans
21
22
23
if __name__ == "__main__":
24
arr = list(map(int, input().split(" ")))
25
print(maxSubarraySum(arr))
26
+ import doctest
27
+ doctest.testmod()
0 commit comments