Given an unsorted array **arr**[] of **N** integers and a **sum**. The task is to count the number of subarrays which add to a given number.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer N denoting the size of the array. The next line contains N space separated integers forming the array. The last line contains an integer denoting the value of the sum.

**Output:**

Print the count of the subarray which adds to the given sum.

**Constraints:**

1 <= T <= 200

1 <= N <= 10^{5}

-10^{5} <= arr[i] <= 10^{5}

-10^{5} <= sum <= 10^{5}

**Example:
Input:**

2

5

10 2 -2 -20 10

-10

6

1 4 20 3 10 5

33

**Output:**

3

1

**Explanation:
Testcase 1:** Subarrays with sum -10 are: [10, 2, -2, -20], [2, -2, -20, 10] and [-20, 10].

Author: Ayush Govil 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 489 |

sudeep235poojary | 302 |

VithalNakod | 272 |

AshutoshPal1 | 254 |

go__karuna | 253 |

Soseph_Jtalin | 792 |

AshutoshPal1 | 722 |

architjindal__ | 648 |

go__karuna | 577 |

ArbazGrewal | 527 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.