How can i print the subarray of maximum sum in kadane’s algorithm?
code link-https://ide.codingblocks.com/s/117422
This code doesn’t seems to be working.
How can i print the subarray of maximum sum in kadane’s algorithm?
code link-https://ide.codingblocks.com/s/117422
This code doesn’t seems to be working.
hey @shubhamshagy, some small change to be done in your code, here there are https://ide.codingblocks.com/s/117554
even in your code if i replace “I=i+1” to “I=i”…i am getting the same subarray no element missing …why??
hey @shubhamshagy, subarray will be from left to right, so to get the subarray print a[left] to a[right].
one more quest- suppose i am given an array {1,2,3,4,5} and i want to print the subarray whose sum is 7 ,so how to do it using kadane 'algo?
using brute force method i am able to do so,but don’t know how to do it using kadane method.
hey @shubhamshagy, kadane is not designed for that. It is to found maximum sum subarray. If you want to do that,one thing you can do is to check whether maxSum is becoming equal to 7 or not,at end of each iteration.