C++ Solution (Kadens Algo) with explanaion.
\n\nonly three cases can be there.\n\nCase 1 :\n\t\t\twhen the sum of entire array is positive.\n \t\t\tans = maximumSuffixSum + arraySum(k-2) + maximumPrefixSu
![image](https://assets.leetcode.com/users/images/a1e9785f-03a5-4111-a665-e9c8b73ce7ad_1666284414.5443702.png)\n\nonly three cases can be there.\n\n**Case 1 :**\n\t\t\twhen the sum of entire array is positive.\n* \t\t\tans = maximumSuffixSum + arraySum*(k-2) + maximumPrefixSum\n**Case 2 :**\n\t\t\twhen the maximum sum comes in only one array,irrespective of value of k.\n* \t\t\tans = KadensAlgoSum\n**Case 3 :**\n\t\t\twhen the sum of entire array is neagitive,take the MaximumSuffixSum + MaximumPrefixSum\n* \t\t\tans = maximumSuffixSum + maximumPrefixSum\n\n\nSo answer will be\n\n* \t\t\tTake the maximum value of all the three cases.\n\n**Code :**\n```\nint kConcatenationMaxSum(vector<int>& arr, int k) {\n\tint n = arr.size(),gsum = 0,sum = 0,gMax = 0,cMaxSum = 0,mod = 1e9+7;\n\tgsum = accumulate(arr.begin(),arr.end(),gsum);\n\tint maxSuf = gsum,maxPre = 0;\n\tfor(int i = 0 ; i < n ; i++){\n\t\tsum += arr[i];\n\t\tmaxSuf = max(maxSuf,gsum-sum);\n\t\tmaxPre = max(sum,maxPre);\n\t\tcMaxSum = max(cMaxSum+arr[i],arr[i]);\n\t\tgMax = max(gMax,cMaxSum);\n\t}\n\n\tif(k == 1) return gMax;\n\treturn (max(max(0ll,(long long)(k-2)*sum)+maxSuf+maxPre,(long long)gMax))%mod;\n}\n```
['C']