Backend Engineer
Senior
programming
Given an array of integers nums and an integer k, return the maximum sum of a subarray of size k. A subarray is a contiguous part of the array. You must solve it in O(n) time complexity. ### Constraints: - 1 <= nums.length <= 2 * 10^4 - -10^5 <= nums[i] <= 10^5 - 1 <= k <= nums.length ### Examples: 1. Input: nums = [2, 1, 5, 1, 3, 2], k = 3 Output: 9 Explanation: Subarray [5, 1, 3] has the maximum sum of 9. 2. Input: nums = [1, 2, 3, 4, 5], k = 2 Output: 9 Explanation: Subarray [4, 5] has the maximum sum of 9.
Suggested Answer