Help me out int his


I checeked ur code
Can’t find any possible problem leading to tle

Let me check again … … . .

@Kartikkhariwal1 okay have a look definetely have some problem

    for(int right =0;right<n;right++) 
    {
        vector<int> temp(mat[0].size(),0); //took it here to save some time
        for(int left =right;left<n;left++)
        {
            for(int k=0;k<row;k++)
            {
                temp[k]+=mat[left][k]; 
            }
            int res=maxsum(temp,k); //instead of calling function do that part here this will also save some time 
            if(res>ans)
            {
                ans=res;
            }
        }
    }

Try this

Here check this

    int ans = INT_MIN;
    int ySize = m.size();
    int xSize = m[0].size();
    for (int l = 0; l < xSize; ++l) {
        vector<int> sums(ySize, 0);
        for (int r = l; r < xSize; ++r) {
            for (int y = 0; y < ySize; ++y)
                sums[y] += m[y][r];
            int accSum = 0;
            set<int> accSet{0};
            for (int sum : sums) {
                accSum += sum;
                auto it = accSet.lower_bound(accSum - k);
                if (it != accSet.end()) {
                    ans = max(ans, accSum - *it);
                }
                accSet.insert(accSum);
            }
        }
    }
    return ans;

Its working fine and is same as urs logic

@Kartikkhariwal1 thanks brother that calling function taking some time

1 Like

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.

@KartikKhariwal https://leetcode.com/problems/word-break-ii/
https://ide.codingblocks.com/s/391232

Hey @shivammishra20121999
open new doubt for different question :slight_smile:

@Kartikkhariwal1 can you explain me here

@Kartikkhariwal1 it is giving same output but it is showing wrong answer