Find the starting and ending index of Smallest sum contiguous subarray in C++
I am trying to find the starting and ending index of the Smallest sum contiguous subarray. I tried many times but I could not able to find.
Can Anyone help me out with this in C++ ?
Code for finding Smallest sum contiguous subarray :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
min_ending_here = arr[i];
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
}
cout<<"minimum sum = "<<min_so_far;
}
Output: minimum sum = -6
c++ kadanes-algorithm
add a comment |
I am trying to find the starting and ending index of the Smallest sum contiguous subarray. I tried many times but I could not able to find.
Can Anyone help me out with this in C++ ?
Code for finding Smallest sum contiguous subarray :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
min_ending_here = arr[i];
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
}
cout<<"minimum sum = "<<min_so_far;
}
Output: minimum sum = -6
c++ kadanes-algorithm
1
What makes you think-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.
– Sid S
Nov 21 '18 at 6:22
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
1
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27
add a comment |
I am trying to find the starting and ending index of the Smallest sum contiguous subarray. I tried many times but I could not able to find.
Can Anyone help me out with this in C++ ?
Code for finding Smallest sum contiguous subarray :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
min_ending_here = arr[i];
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
}
cout<<"minimum sum = "<<min_so_far;
}
Output: minimum sum = -6
c++ kadanes-algorithm
I am trying to find the starting and ending index of the Smallest sum contiguous subarray. I tried many times but I could not able to find.
Can Anyone help me out with this in C++ ?
Code for finding Smallest sum contiguous subarray :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
min_ending_here = arr[i];
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
}
cout<<"minimum sum = "<<min_so_far;
}
Output: minimum sum = -6
c++ kadanes-algorithm
c++ kadanes-algorithm
asked Nov 21 '18 at 6:19


Vishal SrivastavVishal Srivastav
728
728
1
What makes you think-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.
– Sid S
Nov 21 '18 at 6:22
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
1
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27
add a comment |
1
What makes you think-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.
– Sid S
Nov 21 '18 at 6:22
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
1
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27
1
1
What makes you think
-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.– Sid S
Nov 21 '18 at 6:22
What makes you think
-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.– Sid S
Nov 21 '18 at 6:22
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
1
1
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27
add a comment |
2 Answers
2
active
oldest
votes
Assuming that if there exists multiple contiguous sub-arrays with minimum sum we will take the one with minimum starting index, we may modify above solution as below:
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int last_idx = 0; // indication of fresh start of contiguous summation
int start_idx; // for holding start index
int end_idx; // for holding end index
for (int i=0; i<n; i++) {
if (min_ending_here > 0) {
min_ending_here = arr[i];
last_idx = i;
}
else {
min_ending_here += arr[i];
}
if (min_so_far > min_ending_here) {
min_so_far = min_ending_here;
start_idx = last_idx;
end_idx = i;
}
}
cout<<"minimum sum = "<<min_so_far<<endl;
cout<<"start index = "<<start_idx<<endl;
cout<<"end index = "<<end_idx<<endl;
}
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
add a comment |
I tested it with 2 arrays (current ( the result is [1,4]) and commented (the result is [3,3]), see the code):
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
//int arr = {2, 6, 8, 1, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int infimum = INT_MAX; // hold minimum value.
std::pair<int, int> idx(-1, -1); // subarray's indexes
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
{
min_ending_here = arr[i];
}
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
// indexes addition
if( min_so_far == min_ending_here)
{
infimum = min(arr[i], infimum);
if( infimum == arr[i] )
{
idx.first = i;
}
idx.second = i;
}
// << indexes addition
}
cout<<"minimum sum = "<<min_so_far << " indexes: " << idx.first << " " << idx.second;
}
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406284%2ffind-the-starting-and-ending-index-of-smallest-sum-contiguous-subarray-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that if there exists multiple contiguous sub-arrays with minimum sum we will take the one with minimum starting index, we may modify above solution as below:
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int last_idx = 0; // indication of fresh start of contiguous summation
int start_idx; // for holding start index
int end_idx; // for holding end index
for (int i=0; i<n; i++) {
if (min_ending_here > 0) {
min_ending_here = arr[i];
last_idx = i;
}
else {
min_ending_here += arr[i];
}
if (min_so_far > min_ending_here) {
min_so_far = min_ending_here;
start_idx = last_idx;
end_idx = i;
}
}
cout<<"minimum sum = "<<min_so_far<<endl;
cout<<"start index = "<<start_idx<<endl;
cout<<"end index = "<<end_idx<<endl;
}
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
add a comment |
Assuming that if there exists multiple contiguous sub-arrays with minimum sum we will take the one with minimum starting index, we may modify above solution as below:
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int last_idx = 0; // indication of fresh start of contiguous summation
int start_idx; // for holding start index
int end_idx; // for holding end index
for (int i=0; i<n; i++) {
if (min_ending_here > 0) {
min_ending_here = arr[i];
last_idx = i;
}
else {
min_ending_here += arr[i];
}
if (min_so_far > min_ending_here) {
min_so_far = min_ending_here;
start_idx = last_idx;
end_idx = i;
}
}
cout<<"minimum sum = "<<min_so_far<<endl;
cout<<"start index = "<<start_idx<<endl;
cout<<"end index = "<<end_idx<<endl;
}
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
add a comment |
Assuming that if there exists multiple contiguous sub-arrays with minimum sum we will take the one with minimum starting index, we may modify above solution as below:
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int last_idx = 0; // indication of fresh start of contiguous summation
int start_idx; // for holding start index
int end_idx; // for holding end index
for (int i=0; i<n; i++) {
if (min_ending_here > 0) {
min_ending_here = arr[i];
last_idx = i;
}
else {
min_ending_here += arr[i];
}
if (min_so_far > min_ending_here) {
min_so_far = min_ending_here;
start_idx = last_idx;
end_idx = i;
}
}
cout<<"minimum sum = "<<min_so_far<<endl;
cout<<"start index = "<<start_idx<<endl;
cout<<"end index = "<<end_idx<<endl;
}
Assuming that if there exists multiple contiguous sub-arrays with minimum sum we will take the one with minimum starting index, we may modify above solution as below:
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr = {3, -4, 2, -3, -1, 7, -5};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int last_idx = 0; // indication of fresh start of contiguous summation
int start_idx; // for holding start index
int end_idx; // for holding end index
for (int i=0; i<n; i++) {
if (min_ending_here > 0) {
min_ending_here = arr[i];
last_idx = i;
}
else {
min_ending_here += arr[i];
}
if (min_so_far > min_ending_here) {
min_so_far = min_ending_here;
start_idx = last_idx;
end_idx = i;
}
}
cout<<"minimum sum = "<<min_so_far<<endl;
cout<<"start index = "<<start_idx<<endl;
cout<<"end index = "<<end_idx<<endl;
}
answered Nov 21 '18 at 9:45
Bishal GautamBishal Gautam
810517
810517
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
add a comment |
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
@Vishal Srivastav, If above solution helped you, you may mark this as Accepted so that it may help future users in similar problem. Thanks !!
– Bishal Gautam
Nov 21 '18 at 11:48
add a comment |
I tested it with 2 arrays (current ( the result is [1,4]) and commented (the result is [3,3]), see the code):
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
//int arr = {2, 6, 8, 1, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int infimum = INT_MAX; // hold minimum value.
std::pair<int, int> idx(-1, -1); // subarray's indexes
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
{
min_ending_here = arr[i];
}
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
// indexes addition
if( min_so_far == min_ending_here)
{
infimum = min(arr[i], infimum);
if( infimum == arr[i] )
{
idx.first = i;
}
idx.second = i;
}
// << indexes addition
}
cout<<"minimum sum = "<<min_so_far << " indexes: " << idx.first << " " << idx.second;
}
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
add a comment |
I tested it with 2 arrays (current ( the result is [1,4]) and commented (the result is [3,3]), see the code):
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
//int arr = {2, 6, 8, 1, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int infimum = INT_MAX; // hold minimum value.
std::pair<int, int> idx(-1, -1); // subarray's indexes
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
{
min_ending_here = arr[i];
}
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
// indexes addition
if( min_so_far == min_ending_here)
{
infimum = min(arr[i], infimum);
if( infimum == arr[i] )
{
idx.first = i;
}
idx.second = i;
}
// << indexes addition
}
cout<<"minimum sum = "<<min_so_far << " indexes: " << idx.first << " " << idx.second;
}
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
add a comment |
I tested it with 2 arrays (current ( the result is [1,4]) and commented (the result is [3,3]), see the code):
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
//int arr = {2, 6, 8, 1, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int infimum = INT_MAX; // hold minimum value.
std::pair<int, int> idx(-1, -1); // subarray's indexes
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
{
min_ending_here = arr[i];
}
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
// indexes addition
if( min_so_far == min_ending_here)
{
infimum = min(arr[i], infimum);
if( infimum == arr[i] )
{
idx.first = i;
}
idx.second = i;
}
// << indexes addition
}
cout<<"minimum sum = "<<min_so_far << " indexes: " << idx.first << " " << idx.second;
}
I tested it with 2 arrays (current ( the result is [1,4]) and commented (the result is [3,3]), see the code):
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr = {3, -4, 2, -3, -1, 7, -5};
//int arr = {2, 6, 8, 1, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
int infimum = INT_MAX; // hold minimum value.
std::pair<int, int> idx(-1, -1); // subarray's indexes
for (int i=0; i<n; i++)
{
if (min_ending_here > 0)
{
min_ending_here = arr[i];
}
else
min_ending_here += arr[i];
min_so_far = min(min_so_far, min_ending_here);
// indexes addition
if( min_so_far == min_ending_here)
{
infimum = min(arr[i], infimum);
if( infimum == arr[i] )
{
idx.first = i;
}
idx.second = i;
}
// << indexes addition
}
cout<<"minimum sum = "<<min_so_far << " indexes: " << idx.first << " " << idx.second;
}
answered Nov 21 '18 at 7:15


Alexander CherninAlexander Chernin
307210
307210
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
add a comment |
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
wrong answer for arr = {3, -4, 2, -3, -1, -7, -5}; your output is : minimum sum = -18 ( sum is correct ) BUT indexes: 5 6 ( indices are wrong )
– Vishal Srivastav
Nov 21 '18 at 8:19
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
1 upvote for your effort..because no one responded..
– Vishal Srivastav
Nov 21 '18 at 8:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406284%2ffind-the-starting-and-ending-index-of-smallest-sum-contiguous-subarray-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What makes you think
-6
is not the right answer ? The problem is most likely that you output the sum rather than the indexes.– Sid S
Nov 21 '18 at 6:22
-6 is the right answer. but i want to find starting and ending index of this smallest sum contiguous subarray
– Vishal Srivastav
Nov 21 '18 at 6:24
Right, so keep track of the current starting index and the current ending index.
– Sid S
Nov 21 '18 at 6:25
1
Your code shows no attempts to get the indexes. Can you show one of your trials? Further, it would be nice to cite the source of this code :) ... geeksforgeeks.org/smallest-sum-contiguous-subarray
– Everyone
Nov 21 '18 at 6:27