Longest Subarray

1

3 votes
Easy
Problem

Given a linked list containing N integers and an integer K. Your task is to find the length of the longest sub list with sum of the elements equal to the given value K.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two Integers N and K and the second line contains N space separated elements of the list.
Output:
For each test case, print the required length of the longest sub list in new line. If no such sub array can be formed print 0.
Constraints:
1<=T<=500
1<=N,K<=10^5
-10^5<=A[i]<=10^5


Note: Please do consider linked list representation.

Sample Input
3
6 15
10 5 2 7 1 9
6 -5
-5 8 -14 2 4 12
3 6
-1 2 3
Sample Output
4
5
0
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

TestCase 1:
The input array is {10, 5, 2, 7, 1, 9} and the given sum is 15, the sub array {5, 2, 7, 1} will add up to 15. Thus the length of the longest sub list is 4.

Contributers:
Editor Image

?