Skip to content

Commit 51a6516

Browse files
committed
daily
1 parent 468f16c commit 51a6516

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def maxAbsoluteSum(self, nums: List[int]) -> int:
3+
# kadane's but for both min and max
4+
output = abs(nums[0])
5+
minn, maxx = nums[0], nums[0]
6+
7+
return max([(output := max(output, (maxx := max(maxx + num, num)), -(minn := min(minn + num, num)))) for num in nums[1:]] + [output])

my-submissions/m1749.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def maxAbsoluteSum(self, nums: List[int]) -> int:
3+
# kadane's but for both min and max
4+
output = abs(nums[0])
5+
6+
max_sub_arr = nums[0]
7+
min_sub_arr = nums[0]
8+
9+
for num in nums[1:] :
10+
max_sub_arr = max(max_sub_arr + num, num)
11+
min_sub_arr = min(min_sub_arr + num, num)
12+
output = max(output, max_sub_arr, -min_sub_arr)
13+
14+
return output

0 commit comments

Comments
 (0)