AlgoUniversity
  • Go Back
Discussion
Sliding Window Minimum :

Author

HARSH PRIYADARSHI

Difficulty Level : Easy

Submissions : 474

Asked In : ZScaler

Marks :10

: 8 | : 0

You are given an array of $$$n$$$ integers and an integer $$$k$$$ You have to select a window of $$$k$$$ contiguous elements from the array whose sum is minimum.

Input

An integer n, $$$(1 \le n \le 10^6)$$$ and k, $$$(1 \le k \le n)$$$ Next line contains n integers, A1,A2,A3....An $$$(-10^8 \le Ai \le 10^8)$$$

Output

A single integer denoting the minimum sum of contiguous subarray of size k.

Example

Input
5 3
1 3 -1 -4 2
Output
-3

Note

Here, we can see that the segment with -1, -4, 2 gives minimum sum of -3

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.