Skip to content

Practice Maximum Subarray Sum With Length Divisible by K

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3381
LeetCode Problem

Maximum Subarray Sum With Length Divisible by K

Problem Statement

You are given an array of integers nums and an integer k. Return the maximum sum of a subarray of nums, such that the size of the subarray is divisible by k.

Source: Maximum Subarray Sum With Length Divisible by K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2], k = 1
Output
3

# Example 2

Input
nums = [-1,-2,-3,-4,-5], k = 4
Output
-10

# Example 3

Input
nums = [-5,1,2,-3,4], k = 2
Output
4

Constraints

1 <= k <= nums.length <= 2 * 10^5
-10^9 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Subarray Sum With Length Divisible by K.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.