🔥🔥Sum of Imbalance Numbers of all Subarrays 🔥🔥 Easy Approach 🔥🔥Fast & Simple
\n\n# Code\n\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) \n    {\n        int n = nums.size();\n        int ans = 0;\n\n        f
\n\n# Code\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) \n    {\n        int n = nums.size();\n        int ans = 0;\n\n        for(int i = 0; i<n;i++)\n        {\n            unordered_set<int>s;\n            int temp = 0;\n            for(int j = i; j<n; j++)\n            {\n                if(!s.count(nums[j]))\n                {\n                    if(s.count(nums[j]+1) and s.count(nums[j]-1))\n                    {\n                        temp--;\n                    }\n                    else if(!s.empty() and !s.count(nums[j]-1) and !s.count(nums[j]+1))\n                    {\n                        temp++;\n                    }\n                }\n                s.insert(nums[j]);\n                ans += temp;\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'Hash Table']