Skip to content

1749. Maximum Absolute Sum of Any Subarray #1363

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the maximum absolute sum of any subarray (which can be empty) in a given array of integers. The key insight is that the maximum absolute sum can come from either the maximum subarray sum or the minimum subarray sum, considering their absolute values.

Approach

  1. Kadane's Algorithm for Maximum Subarray Sum: This algorithm helps find the maximum sum of any non-empty subarray. We then compare this maximum sum with 0 (the sum of the empty subarray) to determine the overall maximum sum, including the empty subarray.
  2. Modified Kadane's Algorithm for Minimum Subarray Sum: Similarly, we use a modified version of Kadane's algorithm to find the minimum sum of any non-empty subarray. We…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Feb 26, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants