Tap here to switch tabs
Problem
Submissions

Problem: Maximum Good Subarray Sum

Try to solve the Maximum Good Subarray Sum problem.

Statement

You are given an integer array nums of length nn and a positive integer k.

A subarray nums[i..j] is called good if the absolute difference between its first and last elements is equal to k, which means ∣|nums[i] - nums[j]|$ = k$.

Return the maximum sum of a good subarray. If no good subarray can be found, return 00.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Good Subarray Sum

Try to solve the Maximum Good Subarray Sum problem.

Statement

You are given an integer array nums of length nn and a positive integer k.

A subarray nums[i..j] is called good if the absolute difference between its first and last elements is equal to k, which means ∣|nums[i] - nums[j]|$ = k$.

Return the maximum sum of a good subarray. If no good subarray can be found, return 00.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤109\leq 10^9