Skip to content
C

Longest Subarray with Sum K

Mediumjavapythonccppjavascript

Given an integer array and a target K, find the length of the longest contiguous subarray whose sum is exactly K.

Input Format

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

Output Format

Print the length of the longest such subarray, or 0 if none exists.

Input (stdin)

Output

Run your code to see output here...