Longest Subarray of sum K
Medium

Problem Statement

Given an array containing N positive integers and an integer K, your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K.

Examples

1Example 1
Input:
{ "A": [ 4, 1, 1, 1, 2, 3, 5 ], "K": 5 }
Output:
4
2Example 2
Input:
{ "A": [ 10, 5, 2, 7, 1, 9 ], "K": 15 }
Output:
4
3Example 3
Input:
{ "A": [ 1, 2, 3, 4, 5 ], "K": 9 }
Output:
3
Loading...

Sign in to Run Code and Submit