Python- kadane's -simple code
There is a math logic to solve this question\nif k==1 --> simple kadane\'s algo.\n\n \n if sum(arr)>=0--> that means if we multiply this arr more then 2  time t
There is a math logic to solve this question\n**if k==1 --> **simple kadane\'s algo.\n\n \n** if sum(arr)>=0-->** that means if we multiply this arr more then 2  time that is arr=arr*3  then just forget the first and the last concatenated arr and the no. of arr that are in between will make our maximum sum  increase as we increase the count of array in between because if sum (arr)>0 then if we concatenate 2 arrays  in between then also we can take whole 2 array as a part of our required subarray and our sum will increased by  2 times sum(arr)  so now we have to check the no. of element to take from the first array and the last array and the remaining k-2 array in between will contributed fully so just apply kadanes on the first and last array and add the remaining k-2 array sum .**\n \n** if sum(arr)<0-->** then we can find our maximum sum by concatinating just 2 arrays if we concatenate more then 2 then we know sum(arr)<0 so there is no advantage of concatinating more then 2 as they will sum up to negative only \n\njust do some pen paper math by taking some example if you dont understand\n \n```\nclass Solution:\n    def kConcatenationMaxSum(self, arr: List[int], k: int) -> int:\n        if k==1:\n          maxsum=0\n          currentsum=0\n          for i,val in enumerate(arr):\n            currentsum+=val\n            if currentsum<0:\n                currentsum=0\n            maxsum=(max(currentsum,maxsum))\n        elif sum(arr)<0:\n          arr=arr*2\n          maxsum=0\n          currentsum=0\n          for i,val in enumerate(arr):\n            currentsum+=val\n            if currentsum<0:\n                currentsum=0\n            maxsum=(max(currentsum,maxsum))\n            \n        elif sum(arr)>=0:\n          s=sum(arr)   \n          arr=arr*2\n          maxsum=0\n          currentsum=0\n          for i,val in enumerate(arr):\n            currentsum+=val\n            if currentsum<0:\n                currentsum=0\n            maxsum=(max(currentsum,maxsum))\n          maxsum=(maxsum+(k-2)*s)\n        \n        \n        \n        \n        return maxsum%1000000007\n```
['Python']