c++ || simple and well explained solution with comments || kadens Algo
\nclass Solution {\npublic:\n    \n    \n    long long max(long long a,long long b)\n    {\n        if(a>b)return a;return b;\n    }\n    \n    \n    int kConca
```\nclass Solution {\npublic:\n    \n    \n    long long max(long long a,long long b)\n    {\n        if(a>b)return a;return b;\n    }\n    \n    \n    int kConcatenationMaxSum(vector<int>& arr, int k) {\n        \n        long long s=0;\n        int md=1e9+7;\n        long long n=arr.size();\n        \n        //finding the sum of all elements\n        for(auto x:arr)s+=x;\n        \n        //if s>0 we can select all k arrays or we can select all k arrays and exclude the\n        // first -ve and last -ve elements from total sum\n        \n        if(s>0)\n        {\n            long long t=0,mi1=INT_MAX,mi2=INT_MAX;\n            \n            //finding the min including first element\n            for(int i=0;i<n;i++)\n            {\n                t+=arr[i];\n                mi1=min(mi1,t);\n            }\n            \n            //finding the min including last element\n            t=0;\n            for(int i=n-1;i>=0;i--)\n            {\n                t+=arr[i];\n                mi2=min(mi2,t); \n            }\n            \n            //if mi1 or mi2 >0 then we dont need them as they will subtract out our total sum\n            if(mi1>0)mi1=0;\n            if(mi2>0)mi2=0;\n            \n            mi1=abs(mi1);\n            mi2=abs(mi2);\n            long long e=s*k;\n            return max(e,e+mi1+mi2)%md;\n        }\n        \n        \n        //if s<0 then we need only two arrays \n        if(k!=1)for(int i=0;i<n;i++)arr.push_back(arr[i]);\n        long long cm=0,maxsofar=0;\n        for(auto x:arr)\n        {\n            cm=max(cm+x,x);\n            maxsofar=max(maxsofar,cm);\n        }\n        return maxsofar%md;\n        \n    }\n};\n```
[]