Simple CPP | Extended Kadanes
\nclass Solution {\npublic:\n    int kadanes(vector<int> &arr){\n        int max_sum = INT_MIN;\n        int sum = 0;\n        \n        for(int i = 0; i < arr.
```\nclass Solution {\npublic:\n    int kadanes(vector<int> &arr){\n        int max_sum = INT_MIN;\n        int sum = 0;\n        \n        for(int i = 0; i < arr.size(); i++){\n            sum += arr[i];\n            \n            max_sum = max(sum, max_sum);\n            \n            if(sum < 0) sum = 0;\n        }\n        return max_sum;\n    }\n    \n    int kadaneForTwo(vector<int> nums){\n        int arr[nums.size()*2];\n        \n        for(int i = 0; i < nums.size(); i++){\n            arr[i] = nums[i];\n        }\n        \n        for(int i = 0; i < nums.size(); i++){\n            arr[i+ nums.size()] = nums[i];\n        }\n        \n        int max_sum = INT_MIN, sum = 0;\n        \n        for(int i = 0; i < nums.size()*2; i++){\n            sum += arr[i];\n            max_sum = max(max_sum, sum);\n            \n            if(sum < 0) sum = 0;\n        }\n        \n        return max_sum;\n    }\n    \n    int kConcatenationMaxSum(vector<int>& arr, int k) {\n        long long sum = 0;\n        long long ans = 0;\n        for(int i = 0; i < arr.size(); i++){\n            sum += arr[i];\n        }\n        \n        if(k == 1){\n            ans =  kadanes(arr) % 1000000007;\n        } else if(sum < 0){\n            ans = kadaneForTwo(arr) % 1000000007;\n        } else {\n            ans = (kadaneForTwo(arr) + (k-2)*sum) % 1000000007;\n        }\n        if(ans < 0){\n            return 0;\n        }\n        return ans;\n    }\n};\n```
['C++']