Skip to content

Commit 5d40e4e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a20cd7d commit 5d40e4e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

data_structures/arrays/longest_subarray_with_given_sum.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
The algorithm uses a hash map to track cumulative sums and efficiently find subarrays.
77
"""
88

9+
910
class LongestSubarrayWithGivenSum:
1011
def __init__(self, array: list[int]) -> None:
1112
self.array = array
@@ -42,7 +43,9 @@ def find_longest_subarray(self, target_sum: int) -> int:
4243
longest_length = i + 1 # If sum equals target from index 0
4344

4445
if current_sum - target_sum in prefix_sum_map:
45-
longest_length = max(longest_length, i - prefix_sum_map[current_sum - target_sum])
46+
longest_length = max(
47+
longest_length, i - prefix_sum_map[current_sum - target_sum]
48+
)
4649

4750
if current_sum not in prefix_sum_map:
4851
prefix_sum_map[current_sum] = i
@@ -52,4 +55,5 @@ def find_longest_subarray(self, target_sum: int) -> int:
5255

5356
if __name__ == "__main__":
5457
import doctest
58+
5559
doctest.testmod()

0 commit comments

Comments
 (0)