Subarray Sums I Problem Statement

You are provided with an array of positive integers ARR that represents the strengths of different “jutsus” (ninja techniques). You are also given the strength of the enemy S, which is a positive integer.

Your task is to count the number of subarrays whose combined strength matches the given enemy strength S.

Example:

Input:
ARR = [3, 1, 2, 4], S = 6
Output:
2
Explanation:

The subarrays from ARR that sum up to the strength 6 are ARR[0...2] and ARR[2...3].

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 10^3
  • 1 <= ARR[i] <= 10^9
  • 1 <= S <= 10^9
  • Where ARR[i] is the ith element of array ARR.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.

Input Format:

The first line of input contains a single integer T denoting the number of test cases. Then, for each test case: The first line contains two space-separated integers: N (length of the ARR) and S (strength of the enemy). The next line contains N space-separated integers, representing the elements of ARR.

Output Format:

For each test case, return the number of subarrays that sum up to the given strength S of the enemy. Output for each test case should be in a separate line.
Be the first one to answer
Add answer anonymously...
SAP Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter