Last Updated: 9 Oct, 2025

Fixed-Size Subarray Sum

Moderate
Asked in company
UKG (Ultimate Kronos Group)

Problem statement

You are given an array of integers arr of size N, an integer K, and a target value Sum. Your task is to determine if there exists a contiguous subarray of size exactly K whose elements sum up to the given Sum.


If such a subarray exists, you should report "YES". Otherwise, you should report "NO".


Input Format:
The first line of input contains a single integer N, the size of the array.

The second line contains N space-separated integers, representing the elements of the array arr.

The third line contains two space-separated integers, K and Sum.


Output Format:
Print a single string, either "YES" or "NO".


Note:
A brute-force approach of checking every possible subarray of size K would be too slow. An efficient approach like the sliding window technique is required to solve this problem within the given time limits.