C++ Easy Solution
Code\n\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) \n    {\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;i
# Code\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) \n    {\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;i<n-1;i++)\n        {\n            set<int>Set;\n            int cnt=0;\n            for(int j=i;j<n;j++)\n            {\n                if(!Set.count(nums[j]))\n                {\n                    if(!Set.count(nums[j]-1))cnt+=1;\n                    if(Set.count(nums[j]+1))cnt-=1;\n                    Set.insert(nums[j]);\n                }\n                ans+=cnt-1;\n            }\n        }\n        return ans;\n    }\n};\n```
['Ordered Set', 'C++']