|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-subarray-sum-with-length-divisible-by-k/description/?envType=daily-question&envId=2025-11-27">3653. Maximum Subarray Sum With Length Divisible by K</a></h2><h3>Medium</h3><hr><p>You are given an array of integers <code>nums</code> and an integer <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>Return the <strong>maximum</strong> sum of a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code>, such that the size of the subarray is <strong>divisible</strong> by <code>k</code>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<div class="example-block"> |
| 9 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,2], k = 1</span></p> |
| 10 | + |
| 11 | +<p><strong>Output:</strong> <span class="example-io">3</span></p> |
| 12 | + |
| 13 | +<p><strong>Explanation:</strong></p> |
| 14 | + |
| 15 | +<p>The subarray <code>[1, 2]</code> with sum 3 has length equal to 2 which is divisible by 1.</p> |
| 16 | +</div> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<div class="example-block"> |
| 21 | +<p><strong>Input:</strong> <span class="example-io">nums = [-1,-2,-3,-4,-5], k = 4</span></p> |
| 22 | + |
| 23 | +<p><strong>Output:</strong> <span class="example-io">-10</span></p> |
| 24 | + |
| 25 | +<p><strong>Explanation:</strong></p> |
| 26 | + |
| 27 | +<p>The maximum sum subarray is <code>[-1, -2, -3, -4]</code> which has length equal to 4 which is divisible by 4.</p> |
| 28 | +</div> |
| 29 | + |
| 30 | +<p><strong class="example">Example 3:</strong></p> |
| 31 | + |
| 32 | +<div class="example-block"> |
| 33 | +<p><strong>Input:</strong> <span class="example-io">nums = [-5,1,2,-3,4], k = 2</span></p> |
| 34 | + |
| 35 | +<p><strong>Output:</strong> <span class="example-io">4</span></p> |
| 36 | + |
| 37 | +<p><strong>Explanation:</strong></p> |
| 38 | + |
| 39 | +<p>The maximum sum subarray is <code>[1, 2, -3, 4]</code> which has length equal to 4 which is divisible by 2.</p> |
| 40 | +</div> |
| 41 | + |
| 42 | +<p> </p> |
| 43 | +<p><strong>Constraints:</strong></p> |
| 44 | + |
| 45 | +<ul> |
| 46 | + <li><code>1 <= k <= nums.length <= 2 * 10<sup>5</sup></code></li> |
| 47 | + <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> |
| 48 | +</ul> |
0 commit comments