#How is my returning vector full of zeros , i cant understand why

9 messages · Page 1 of 1 (latest)

sullen dagger
#
       {
        vector<int> ans(code.size(),0);
        for(int i=0;i<code.size();i++)
        {
            int n = 0;
            for(int j=1;j<k+1;j++)
            {
                int x = (i-j+code.size())%code.size();
                n = n + code[x];
            }
            ans[i] = n;
        }
        return ans;
       }```
weak wrenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

sullen dagger
#

its starting to hurt my brain

mortal geyser
#

Since
k < 0 and 1 <= j
implies that
k+1 <= 0 < 1 <= j
So the inner for never gets run and n is always 0 so ans[i] = 0? Unless Im missing something

sullen dagger
#

ur a life saver

#

didnt thought of it

#

😭 😭

#

!solved