
Given an unsorted array of integers, find a subarray which adds to a given number. If there are more than one subarrays with the sum as the given number, print any of them.
Examples:
Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33
Ouptut: Sum found between indexes 2 and 4
Input: arr[] = {10, 2, -2, -20, 10}, sum = -10
Ouptut: Sum found between indexes 0 to 3
Input: arr[] = {-10, 0, 2, -2, -20, 10}, sum = 20
Ouptut: No subarray with given sum exists
Numbers are positive.
1 |
vector<pair<int, int>> subArraySum(vector<int> nums, int sum){ |
Numbers are negative.
1 |
vector<pair<int, int>> neSubArraySum(vector<int> nums, int sum){ |




近期评论