✅Beats 100%✅Dirty Code but useful
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n\n    private:\n    int N=1e9+7;\n        <!-- Maximum Sum Circular Subarray leetcode question No-918 -->\n        int maxSubarraySumCircular(vector<int>& nums) {\n            int n=nums.size();\n            int maxi=INT_MIN;\n            int mini=INT_MAX;\n            int sum=0;\n            int tempmax=0;\n            int tempmin=0;\n            for(auto &i:nums){\n                tempmax+=i;\n                tempmin+=i;\n                sum+=i;\n                maxi=max(maxi,tempmax);\n                mini=min(mini,tempmin);\n                if(tempmax<0) tempmax=0;\n                if(tempmin>0) tempmin=0;\n            }\n\n            if(maxi<=0) return *max_element(nums.begin(),nums.end());\n            if(mini>=0) return sum;\n            return max(maxi,sum-mini);\n        }\n        int maxSubarraySumCircularnew(vector<int>& nums) {\n            vector<int> V(nums.begin(),nums.end());\n            V.insert(V.end(),nums.begin(),nums.end());\n            long long ans=0;\n            long long temp=0;\n            for(auto &i:V){\n                temp+=i;\n                ans=max(ans,temp);\n                if(temp<0) temp=0;\n            }\n            return ans%N;\n        }\npublic:\n    int kConcatenationMaxSum(vector<int>& arr, int k) {\n        int n=arr.size();\n        int sum=accumulate(arr.begin(),arr.end(),0);\n\n        if(k==1){\n            sum=0;\n            int tempsum=0;\n            for(auto &i:arr){\n                tempsum+=i;\n                sum=max(sum,tempsum);\n                if(tempsum<0) tempsum=0;\n            }\n            return sum;\n        }\n        else{\n            if(sum>=0){\n            int maxa=maxSubarraySumCircularnew(arr);\n            long long ans=maxa;\n            ans = (ans + (1LL * (sum % N) * ((k - 2) % N)) % N) % N;\n\n            return int(ans%N);\n            }\n            else{\n                int maxa=maxSubarraySumCircular(arr);\n                if(maxa<0) maxa=0;\n                return maxa;\n            }\n        }\n\n\n    }\n};\n```
['C++']