Good solution with kadane's algorithm c++
class Solution {\npublic:\n    \n    /\n    \n    Observation is key for this problem\n    \n    if you clearly observer we get some pattern after k>2\n    \n  
class Solution {\npublic:\n    \n    /*\n    \n    Observation is key for this problem\n    \n    if you clearly observer we get some pattern after k>2\n    \n    k=3 sol= maximum subarray sum of array when its repeated twice + total sum *(1)\n    k=4 sol= subarraysum + totalsum*(2)\n    \n    recurrance relation is kadanesum(k=2) + totalsum*(k-2)    \n    */\n    int mod=1e9+7;\n    int kadane(vector<int>&arr)\n    {\n        int sum=0;\n        int ans=0;\n        int incl=0;\n        \n        for(auto i:arr)\n        {\n            sum+=i;\n            if(sum>incl)\n            {\n                incl=sum;\n            }\n            if(sum<0)\n            {\n                sum=0;\n            }\n            ans=max(ans,incl);\n        }\n        return ans;\n    }\n    int kConcatenationMaxSum(vector<int>& arr, int k) {\n      \n        long long  int ans=kadane(arr);\n     \n        long long   int totalsum=accumulate(arr.begin(),arr.end(),0);\n       \n        if(k==1)\n        {\n            return ans;\n        }\n       \n        \n        \n        vector<int>b(arr.size()*2);\n        for(int i=0;i<arr.size()*2;i++)\n        {\n            b[i]=arr[i%arr.size()];\n        }\n        \n         ans=kadane(b)%mod;\n        if(totalsum>=0)\n        {\n           \n        \n        ans=(ans+(k-2)*totalsum)%mod;\n        }\n        b.clear();\n        \n        if(ans<0) return 0;\n        return ans;\n        \n        \n    }\n};
[]