Welcome to the daily solving of our PROBLEM OF THE DAY with Siddharth Hazra. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Array but will also help you build up problem-solving skills.
In this video, we are given an unsorted array A of size N that contains only positive integers, Our task is to find a continuous sub-array that adds to a given number S and return the left and right index(1-based indexing) of that subarray.
In case of multiple subarrays, return the subarray indexes which come first on moving from left to right.
Example :
Input:
N = 5, S = 12
A[] = {1,2,3,7,5}
Output: 2 4
Explanation: The sum of elements from 2nd position to 4th position is 12.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/b846f4bc-358e-4d60-a046-9a5c06eb7807