Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
* [Find Triplets With 0 Sum](data_structures/arrays/find_triplets_with_0_sum.py)
* [Index 2D Array In 1D](data_structures/arrays/index_2d_array_in_1d.py)
* [Kth Largest Element](data_structures/arrays/kth_largest_element.py)
* [Maximum Subarray Sum](data_structures/arrays/maximum_subarray_sum.py)
* [Median Two Array](data_structures/arrays/median_two_array.py)
* [Monotonic Array](data_structures/arrays/monotonic_array.py)
* [Pairs With Given Sum](data_structures/arrays/pairs_with_given_sum.py)
Expand Down
27 changes: 27 additions & 0 deletions data_structures/arrays/maximum_subarray_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def maxSubarraySum(arr: list[int]) -> int:

Check failure on line 1 in data_structures/arrays/maximum_subarray_sum.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

data_structures/arrays/maximum_subarray_sum.py:1:5: N802 Function name `maxSubarraySum` should be lowercase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/maximum_subarray_sum.py, please provide doctest for the function maxSubarraySum

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: maxSubarraySum

"""
Find the maximum sum of a subarray.

Args:
arr: array of numbers.

Returns:
Maximum sum possible in a subarray
"""
ans = arr[0]

for i in range(len(arr)):
current_sum = 0

for j in range(i, len(arr)):
current_sum = current_sum + arr[j]
ans = max(ans, current_sum)

return ans


if __name__ == "__main__":
arr = list(map(int, input().split(" ")))
print(maxSubarraySum(arr))
import doctest
doctest.testmod()
Loading