Skip to content
CampusEduX

Maximum Sum of K Consecutive Elements

Easyjavapythonccppjavascript

Given an integer array and a number K, find the maximum sum of any contiguous subarray of exactly K elements.

Input Format

The first line contains two integers N and K. The second line contains N space-separated integers.

Output Format

Print the maximum sum of a window of K consecutive elements.

Related Problems

  • Two Sum in Sorted Array
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Remove Duplicates Using Two Pointers
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • First Negative Number in Every Window
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...