{"id":"686ad2e4-0f12-44f2-91ca-8ce39514790c","name":"Maximum Sum Subarray With At Least K Elements","description":"1. You are given an array(arr) of integers and a number k.\r\n2. You have to find maximum subarray sum in the given array.\r\n3. The subarray must have at least k elements.","inputFormat":"A number N\r\na1\r\na2.. N integers\r\nA number K","outputFormat":"A number representing maximum subarray sum with subarray having at least K elements.","constraints":"1 &lt;= N &lt;= 10^5\r\n1 &lt;= arr[i] &lt;= 10^5\r\n1 &lt;= K &lt;= N","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr, int k) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < arr.length; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, k));\r\n }\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n1\r\n2\r\n3\r\n2","sampleOutput":"6\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"c69d14f4-d918-4473-9738-803af0bd3329","name":"Maximum Sum Subarray With At Least K Elements","slug":"maximum-sum-subarray-with-at-least-k-elements","type":1}],"next":{"id":"fcf8a766-4a26-4e79-91cc-59725d5c2686","name":"Maximum sum subarray with at least K elements MCQ","type":0,"slug":"maximum-sum-subarray-with-at-least-k-elements-mcq"},"prev":{"id":"94a18864-34a1-48c1-9005-930199c138c7","name":"K Concatenation","type":3,"slug":"k-concatenation"}}}

Maximum Sum Subarray With At Least K Elements

1. You are given an array(arr) of integers and a number k. 2. You have to find maximum subarray sum in the given array. 3. The subarray must have at least k elements.

{"id":"686ad2e4-0f12-44f2-91ca-8ce39514790c","name":"Maximum Sum Subarray With At Least K Elements","description":"1. You are given an array(arr) of integers and a number k.\r\n2. You have to find maximum subarray sum in the given array.\r\n3. The subarray must have at least k elements.","inputFormat":"A number N\r\na1\r\na2.. N integers\r\nA number K","outputFormat":"A number representing maximum subarray sum with subarray having at least K elements.","constraints":"1 &lt;= N &lt;= 10^5\r\n1 &lt;= arr[i] &lt;= 10^5\r\n1 &lt;= K &lt;= N","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr, int k) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < arr.length; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, k));\r\n }\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n1\r\n2\r\n3\r\n2","sampleOutput":"6\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"c69d14f4-d918-4473-9738-803af0bd3329","name":"Maximum Sum Subarray With At Least K Elements","slug":"maximum-sum-subarray-with-at-least-k-elements","type":1}],"next":{"id":"fcf8a766-4a26-4e79-91cc-59725d5c2686","name":"Maximum sum subarray with at least K elements MCQ","type":0,"slug":"maximum-sum-subarray-with-at-least-k-elements-mcq"},"prev":{"id":"94a18864-34a1-48c1-9005-930199c138c7","name":"K Concatenation","type":3,"slug":"k-concatenation"}}}
plane

Editor


Loading...

Maximum Sum Subarray With At Least K Elements

medium

1. You are given an array(arr) of integers and a number k. 2. You have to find maximum subarray sum in the given array. 3. The subarray must have at least k elements.

Constraints

1 <= N <= 10^5 1 <= arr[i] <= 10^5 1 <= K <= N

Format

Input

A number N a1 a2.. N integers A number K

Output

A number representing maximum subarray sum with subarray having at least K elements.

Example

Sample Input

3 1 2 3 2

Sample Output

6

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode