• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 22, 2024 |73.6K Views

Find subarray with given sum

  Share  2 Likes
Description
Discussion

Given an unsorted array arr of nonnegative integers and an integer sum, find a continuous subarray which adds to a given sum. There may be more than one subarrays with sum as the given sum, print first such subarray. 
Examples :

Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33
Output: Sum found between indexes 2 and 4
Sum of elements between indices 2 and 4 is 20 + 3 + 10 = 33

Find subarray with given sum : https://www.geeksforgeeks.org/find-subarray-with-given-sum/