Easy Understanding Simple C++ Solution
time complexity : O(N * N * logN)\n#### space complexity : O(N)\n\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int ans 
#### time complexity : O(N * N * logN)\n#### space complexity : O(N)\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int ans = 0;\n        int n = nums.size();\n        for(int i=0;i<n-1;i++)\n        {\n            int count = 0; // use for tracking current subarray impbalance numbers .\n            unordered_set<int> st; \n            st.insert(nums[i]);\n            for(int j=i+1;j<n;j++)\n            {\n                // if element already occur does not create any imbalancing\n                if(st.find(nums[j]) != st.end()) {\n                  \n                    if(count>0)\n                      ans += count;\n                    continue;   \n                };\n                \n                int left = nums[j]-1;\n                int right = nums[j]+1;\n                \n               \n                // if both adjacents already present then decrement imbalance\n                if(st.count(left) && st.count(right))\n                {\n                    count--;\n                }else if((st.count(left) == 0) && (st.count(right) == 0))\n                {\n                    // of none is present then increment imbalance\n                    count++;\n                }\n                \n                // consider only those subarray whose imbalance is greater then 0\n                if(count>0)\n                  ans += count;\n                \n                st.insert(nums[j]);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n## upvote please !\n
['C']