Subarray With Given Sum Problem Statement
Given an array ARR
of N integers and an integer S, determine if there exists a contiguous subarray within the array with a sum equal to S. If such a subarray exists, return the start and end indices (0-based index) of the subarray. If no such subarray is found, return [-1, -1].
Example:
Input:
T = 1
N = 4, S = 7
ARR = [1, 2, 3, 4]
Output:
[0, 2]
Explanation:
The subarray [1, 2, 3] has a sum equal to S (7).
Constraints:
1 <= T <= 10
1 <= N <= 10^5
-10^14 <= S <= 10^14
-10^9 <= ARR[i] <= 10^9
- Time Limit: 1 sec
Note: If multiple such subarrays exist, returning any one is sufficient.

AnswerBot
4mo
Given an array of integers, find a contiguous subarray with a given sum.
Iterate through the array while keeping track of the current sum and start index.
Use a hashmap to store the sum and its correspo...read more
Help your peers!
Add answer anonymously...
Hewlett Packard Enterprise Software Developer interview questions & answers
A Software Developer was asked Q. Given a string, return the character counts. For example, input 'aabbbc' should ...read more
A Software Developer was asked Q. Design a classroom management system.
A Software Developer was asked Q. How well can you adapt to changes in technology used for a project? Explain your...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given a string, return the character counts. For example, input 'aabbbc' should ...read more
A Software Developer was asked Q2. Design a classroom management system.
A Software Developer was asked Q3. How well can you adapt to changes in technology used for a project? Explain your...read more
>
Hewlett Packard Enterprise Software Developer Interview 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

