Java Clean Code | Kadane's Algorithm
class Solution {\n\n    public long kadane (int arr[]) {\n        long curr = arr[0];\n        long max = arr[0];\n        for(int i = 1; i < arr.length; i++) {
class Solution {\n\n    public long kadane (int arr[]) {\n        long curr = arr[0];\n        long max = arr[0];\n        for(int i = 1; i < arr.length; i++) {\n            if (curr >= 0) curr+=arr[i];\n            else curr = arr[i];\n            if (curr > max) max = curr;\n        }\n        return max;\n    }\n    public long kadaneTwo(int arr[]) {\n        int narr[] = new int[arr.length * 2];\n        for (int i = 0; i < arr.length; i++) \n            narr[i] = arr[i];\n        for (int i = 0; i < arr.length; i++)\n            narr[i + arr.length] = arr[i];\n        return kadane(narr);\n    }\n    public long sum(int arr[]) {\n        long s = 0;\n        for (int i = 0; i < arr.length; i++)\n            s += arr[i];\n        return s;\n    }\n    public int kConcatenationMaxSum(int[] arr, int k) {\n        long sum = sum(arr);\n        long res = 0;\n        long x = 1000000007;\n        if (k == 1) res = kadane(arr);\n        else if (sum < 0) res = kadaneTwo(arr);\n        else res = kadaneTwo(arr) + (k - 2)*sum;\n        if (res < 0) return 0;\n        return (int)(res % x);\n    }\n}
[]