11. Max Sum Subarray of size K

The problem can be found at the following link: Question Link

My Approach

Easy approach, I use a sliding window approach. I maintain a running sum of the current window and slide the window by subtracting the element that goes out of the window and adding the new element. I update the maximum sum at each step.

Time and Auxiliary Space Complexity

  • Time Complexity: O(N), where N is the size of the array.

  • Auxiliary Space Complexity: O(1).

Code (C++)

Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.

If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.

Last updated

Was this helpful?