Help me out in this


Hey @shivammishra20121999
int max_so_far = INT_MIN
max so far shouldnt start from a[0]

Also Your logic is incorrect. There might be a modification of Kadane which will work but definitely not this one. Use your Kadane function for arr=[-2,-3,11], k=8. Your function gives -2 but it should be 8. Think about why and where your logic is incorrect.

Correct method :

You just need to change the function that you made. Maintain prefix sums in a set and let prefix sum at some index i equals S, then use binary search to find if there exists a prefix sum greater than or equal to S-k, and use it to update your answer. You can use lower_bound for it.

you can see this:

@aa1 https://ide.codingblocks.com/s/389989
this is my code passing 26 out of 27 but giving tle in last test case

@aa1 are u there abha ??

see this for tle :