C++ Kadane's Algo
\nclass Solution {\npublic:\n    \n    int M = pow(10, 9) + 7;\n    \n    int Kadane(vector<int>& arr)\n    {\n        long csum = arr[0];\n        long osum = 
```\nclass Solution {\npublic:\n    \n    int M = pow(10, 9) + 7;\n    \n    int Kadane(vector<int>& arr)\n    {\n        long csum = arr[0];\n        long osum = arr[0];\n        \n        for(int i=1; i<arr.size(); i++)\n        {\n            csum = max(csum + arr[i], (long)arr[i]);\n            osum = max(csum, osum);\n        }\n        \n        return osum;\n    }\n    \n    int kConcatenationMaxSum(vector<int>& arr, int k) \n    {\n        int osize = arr.size();\n        \n        if(arr.empty() || k==0)\n            return 0;\n        \n        if(arr.size() == 1)\n            return arr[1];\n        \n        long sum = 0; //sum of the array\n        \n        for(int i=0; i<arr.size(); i++)\n            sum+=arr[i];\n        \n        if(k == 1)\n            return Kadane(arr);\n        \n        //for K==2\n        \n        arr.resize(2*arr.size());\n      \n        for(int i=0; i<osize; i++)\n           arr[osize + i] = arr[i];\n        \n        int Kres = Kadane(arr);\n        \n        if(Kres < 0)\n            return 0; //length of subarray is zero\n        \n        else\n        {\n            if(sum > 0)\n                return (Kres + (k-2)*sum)%M;\n            \n            else\n                return Kres%M;\n        }\n        \n        \n    }\n};\n\n```
[]