Hi I am getting a tle i guess due to O(n^3) can anyone please help me with this?
SubArray TLE HELP
Hi @idontknowhowtocode
You are facing TLE because of because complexity of your program is of O(n^3). To get rid of TLE you have to use Kadane’s Algorithm.
According to this algorithm :
-
Initialize:
max_so_far = 0
max_ending_here = 0 -
Loop for each element of the array
(a) max_ending_here = max_ending_here + a[i]
(b) if(max_ending_here < 0)
max_ending_here = 0
© if(max_so_far < max_ending_here)
max_so_far = max_ending_here -
return max_so_far
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.