Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 433 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

Given an array containing **N** integers and an integer **K**. Your task is to find the length of the longest Sub-Array 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 array.

**Output:**

For each test case, print the required lenght of the longest Sub-Array 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}

**Example:
Input:**

3

6 15

10 5 2 7 1 9

6 -5

-5 8 -14 2 4 12

3 6

-1 2 3

4

5

0

TestCase 1:

```
Input : arr[] = { 10, 5, 2, 7, 1, 9 },
K = 15
Output : 4
The sub-array is
```**{5, 2, 7, 1}**.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Longest Sub-Array with Sum K

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.