public int maxDiffSubArrays(ArrayList<Integer> nums) {
        // write your code
        if (nums == null || nums.size() == 0)
            return 0;
        int n = nums.size();
        int[] leftMax = new int[n];
        int[] leftMin = new int[n];
        int[] rightMax = new int[n];
        int[] rightMin = new int[n];
        int sum = 0, max = Integer.MIN_VALUE, minSum = 0, min = Integer.MAX_VALUE, maxSum = 0;
        for (int i = 0; i < n; ++i) {
            sum += nums.get(i);
            max = Math.max(max, sum - minSum);
            min = Math.min(min, sum - maxSum);
            maxSum = Math.max(maxSum, sum);
            minSum = Math.min(sum, minSum);
            leftMax[i] = max;
            leftMin[i] = min;
        }
        sum = 0;
        min = Integer.MAX_VALUE;
        minSum = 0;
        maxSum = 0;
        max = Integer.MIN_VALUE;
        for (int i = n - 1; i >= 0; --i) {
            sum += nums.get(i);
            min = Math.min(min, sum - maxSum);
            max = Math.max(max, sum - minSum);
            maxSum = Math.max(maxSum, sum);
            minSum = Math.min(minSum, sum);
            rightMin[i] = min;
            rightMax[i] = max;
        }
        int ans = 0;
        for (int i = 0; i < n - 1; ++i) {
            ans = Math.max(ans, Math.max(Math.abs(leftMax[i] - rightMin[i + 1]), Math.abs(leftMin[i] - rightMax[i + 1])));
        }
        return ans;
    }