Find continuous subarray/subsequence with given sum
void subarr ( int arr[] ,int n , int sum){ map < int,int > map ; int curr_sum= 0 ; for ( int i= 0 ; i<n ; i++){ curr_sum+=arr[i] ; if (curr_sum==sum){ cout << "Sum found between " << 0 << " and " << i << endl ; return; } if (map.find(curr_sum-sum) != map.end()){ cout << "Sum found between " << map [ curr_sum-sum]+ 1 << " and " << i << endl ; return; } map [ curr_sum]=i ; } cout << "No Subarray found " << endl ; }