hashing 48ms
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int sumImbalanceNumbers(vector<int>& nums) {
        int s=0, n=nums.size();
        for(int i=0;i<nums.size();i++){
            vector<int>hash(1003, 0);
            int mx=nums[i], mn=nums[i];
            hash[mx]++;
            int pre=0;
            for(int j=i+1;j<nums.size();j++){
                int curr=pre, k=0, diff=0;
                if(hash[nums[j]]==0){
                    if(nums[j]>mx){
                        if(nums[j]>mx+1){
                            k=1;
                        }
                        mx=nums[j];
                    }
                    else if(mn>nums[j]){
                        if(mn>nums[j]+1){
                            k=1;
                        }
                        mn=nums[j];
                    }
                    else{
                        if(hash[nums[j]+1]>0&&hash[nums[j]-1]>0){
                            diff--;
                        }else{
                            if(hash[nums[j]+1]==0){
                                k=1;
                            }
                            if(hash[nums[j]-1]>0){
                                diff--;
                            }
                        }
                    }
                    hash[nums[j]]++;
                }
                curr+=(k+diff);
                s+=curr;
                pre=curr;
            }
        }
        return s;
    }
};
```
['Hash Table', 'C++']