import 'dart:io';
void PrintSubarrayWithSumEqualToN(List<int>arr, int N) {
var size = arr.length;
for (var i = 0; i < size; i++) {
var current_sum = arr[i];
if (current_sum == N) {
stdout.write("Sum found at index: " + (i).toString());
return;
}
else {
for (var j = i + 1; j < size; j++) {
current_sum += arr[j];
if (current_sum == N) {
print("Sum found between index " + i.toString() + " and " + j.toString());
for (var k = i; k <= j; k++) {
stdout.write((arr[k]).toString() + " ");
}
return;
}
else {
if (current_sum > N) {
break;
}
}
}
}
}
stdout.write("No subarray found");
}
void main() {
List<int> arr = [2, 5, 8, 9, 1, 7, 12, 21, 19];
var N = 52;
PrintSubarrayWithSumEqualToN(arr, N);
}
/*
run:
Sum found between index 6 and 8
12 21 19
*/