Simplest Solution Using Hashing
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int l=nums.size(),ans=0;\n        for(int i=0;i<l;i++)\n        {\n            vector<int> mp(l+2);\n            int currCnt=0;\n            mp[nums[i]]=1;\n            for(int j=i+1;j<l;j++)\n            {\n                if(mp[nums[j]]==1){\n                    ans+=currCnt;\n                    continue;\n                }\n                mp[nums[j]]=1;\n                if(mp[nums[j]+1]==1 && mp[nums[j]-1]==1){\n                    currCnt--;\n                }\n                if(mp[nums[j]+1]!=1 && mp[nums[j]-1]!=1){\n                    currCnt++;\n                }\n                ans+=currCnt;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']