0
Java query for given code!
Heres my solution to find an subarray for a given sum. But its showing error. Whats the problem in my code? I want outpit with this particular approach only. https://code.sololearn.com/c5JYp89Jgqqz/?ref=app
1 Odpowiedź
+ 2
Change this:
if(sum>resultSum){
sum=0;
left=temp;
temp++;
}
In your code you increment temp and give it to left --> left starts at 2 after the first round but it should start at 1.
And maybe it would be a good idea to add the condition left < right in your while loop --> left = right --> no sum found
-> while(sum <= resultSum && left <= right)