c++ and java simple O(n*n) approach
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)$$ -->\nO(N*N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# C++\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int n=nums.size();\n        if(n==1) return 0;\n        int ans=0;\n        int* arr=new int[n+1];\n        fill(arr,arr+n+1,0);\n        for(int i=0;i<n-1;i++){\n            arr[nums[i]]=1;\n            int mini=nums[i];\n            int imb=0;\n            for(int j=i+1;j<n;j++){\n                if(nums[j]<=mini){\n                    if(nums[j]<mini){\n                        if(nums[j]<mini-1) imb++;\n                        arr[nums[j]]=1;\n                        mini=nums[j];\n                    }\n                }\n                else{\n                    if(arr[nums[j]]==0){\n                        arr[nums[j]]=1;\n                        if(arr[nums[j]-1]==0) imb++;\n                        if(nums[j]+1<=n && arr[nums[j]+1]==1) imb--;\n                    }\n                }\n                ans+=imb;\n            }\n            fill(arr,arr+n+1,0);\n        }\n        return ans;\n    }\n};\n```\n# JAVA\n```\nclass Solution {\n    public int sumImbalanceNumbers(int[] nums) {\n        int n=nums.length;\n        if(n==1) return 0;\n        int ans=0;\n        int arr[]=new int[n+1];\n        for(int i=0;i<n-1;i++){\n            arr[nums[i]]=1;\n            int mini=nums[i];\n            int imb=0;\n            for(int j=i+1;j<n;j++){\n                if(nums[j]<=mini){\n                    if(nums[j]<mini){\n                        if(nums[j]<mini-1) imb++;\n                        arr[nums[j]]=1;\n                        mini=nums[j];\n                    }\n                }\n                else{\n                    if(arr[nums[j]]==0){\n                        arr[nums[j]]=1;\n                        if(arr[nums[j]-1]==0) imb++;\n                        if(nums[j]+1<=n && arr[nums[j]+1]==1) imb--;\n                    }\n                }\n                ans+=imb;\n            }\n            Arrays.fill(arr,0);\n        }\n        return ans;\n    }\n}\n\n```
['C++', 'Java']