Find subarray with given sum | Set 1 (Nonnegative Numbers) - GeeksforGeeks
Given an unsorted array of nonnegative integers, find a continous subarray which adds to a given number.
Examples:
Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33 Ouptut: Sum found between indexes 2 and 4 Input: arr[] = {1, 4, 0, 0, 3, 10, 5}, sum = 7 Ouptut: Sum found between indexes 1 and 4 Input: arr[] = {1, 4}, sum = 0 Output: No subarray found
There may be more than one subarrays with sum as the given sum. The following solutions print first such subarray.
Source: Google Interview Question
Read full article from Find subarray with given sum | Set 1 (Nonnegative Numbers) - GeeksforGeeks
No comments:
Post a Comment