public static int maxDiffSubArrays(List<Integer> nums) {
        // write your code
        int n=nums.size();
        if (n==2)
        	return Math.abs(nums.get(0)-nums.get(1));
        List<Integer>A=nums;
        int[]p1=new int[n],s1=new int[n], p2=new int[n],s2=new int[n];
        p1[0]=p2[0]=A.get(0);
        s1[n-1]=s2[n-1]=A.get(n-1);
        for (int i=1,lmin=A.get(0),lmax=A.get(0);i<n;++i) {
            int a=A.get(i);
            p1[i]=Math.min(lmin=Math.min(a, lmin+a),p1[i-1]);
            p2[i]=Math.max(lmax=Math.max(a, lmax+a),p2[i-1]);
        }
        for (int i=n-2,lmin=A.get(n-1),lmax=A.get(n-1);i>=0;--i) {
            int a=A.get(i);
            s1[i]=Math.min(lmin=Math.min(a, lmin+a),s1[i+1]);
            s2[i]=Math.max(lmax=Math.max(a, lmax+a),s2[i+1]);
        }
        int rel=0;
        for (int i=1;i<n-1;++i) {
            rel=Math.max(Math.abs(p1[i-1]-s2[i]),rel);
            rel=Math.max(Math.abs(p1[i]-s2[i+1]),rel);
            rel=Math.max(Math.abs(p2[i]-s1[i+1]),rel);
            rel=Math.max(Math.abs(p2[i-1]-s1[i]),rel);
        }
        return rel;
    }