
Asked in SAP
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 thei
th element of arrayARR
.
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.

AnswerBot
4mo
Count the number of subarrays whose combined strength matches the given enemy strength.
Iterate through all subarrays and calculate their sum to check if it matches the enemy strength.
Use two pointers ...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at SAP
Q. How would you convert a byte stream to a human-readable format without using ext...read more
Q. Given coins with denominations 1, 2, and 5, what is the minimum number of coins ...read more
Q. How do you find the number of nodes in a tree, and what is the time complexity o...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for SAP Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

