Simple Java Solution
\nclass Solution {\n    public int sumImbalanceNumbers(int[] nums) {\n        int result=0;\n        for(int i=0;i<nums.length-1;i++)\n        {\n            in
```\nclass Solution {\n    public int sumImbalanceNumbers(int[] nums) {\n        int result=0;\n        for(int i=0;i<nums.length-1;i++)\n        {\n            int prev=0;\n            ArrayList<Integer> l=new ArrayList<Integer>();\n            l.add(nums[i]);\n            for(int j=i+1;j<nums.length;j++)\n            {\n                if(j==i+1)\n                {\n                    if(nums[i]>nums[j])\n                    {\n                        l.add(0,nums[j]);\n                    }\n                    else\n                    {\n                        l.add(nums[j]);\n                    }\n                    if(l.get(1)-l.get(0)>1)\n                    {\n                        result++;\n                        prev=1;\n                    }\n                }\n                else\n                {\n                    int index=0;\n                    int low=0,high=l.size()-1;\n                    while(low<=high)\n                    {\n                        int mid=(low+high)/2;\n                        if(l.get(mid)>nums[j])\n                        {\n                            index=mid;\n                            high=mid-1;\n                        }\n                        else\n                        {\n                            index=mid+1;\n                            low=index;\n                        }\n                    }\n                    l.add(index,nums[j]);\n                    if(index==l.size()-1)\n                    {\n                        if(l.get(l.size()-1)-l.get(l.size()-2)>1)\n                        {\n                            result+=(prev+1);\n                            prev++;\n                        }\n                        else\n                        {\n                            result+=prev;\n                        }\n                    }\n                    else if(index==0)\n                    {\n                        \n                        if(l.get(1)-l.get(0)>1)\n                        {\n                            \n                            result+=(prev+1);\n                            prev++;\n                        }\n                        else\n                        {\n                            result+=prev;\n                        }\n                    }\n                    else\n                    {\n                        int r=0;\n                        if(l.get(index)-l.get(index-1)>1)\n                        {\n                            r++;\n                        }\n                        if(l.get(index+1)-l.get(index)>1)\n                        {\n                            r++;\n                        }\n                        if(l.get(index+1)-l.get(index-1)>1)\n                        {\n                            r--;\n                        }\n                        prev=prev+r;\n                        result+=prev;\n                    }\n                }\n            }\n        }\n\n        return result;\n    }\n}\n```
['Java']