C++ || unordered_set
\n\n# Code\n\nclass Solution {\npublic:\n   int sumImbalanceNumbers(vector<int>& A) {\n    int res = 0, n = A.size();\n    for (int i = 0; i < n; ++i) {\n      
\n\n# Code\n```\nclass Solution {\npublic:\n   int sumImbalanceNumbers(vector<int>& A) {\n    int res = 0, n = A.size();\n    for (int i = 0; i < n; ++i) {\n        //create unsorted array\n        unordered_set<int> s;\n        //insert ele one by one\n        s.insert(A[i]); \n        //to store curr imbalance\n        int cur = 0; \n        for (int j = i + 1; j < n; ++j) {\n            //if element is not present\n            if (s.count(A[j]) == 0) { \n               //check if the adj ele are present or not\n                cur += 1 - s.count(A[j] + 1) - s.count(A[j] - 1);\n            }\n            //enter current ele into the set\n            s.insert(A[j]);\n            //add the current element into the res \n            res += cur; \n        }\n    }\n    return res;\n}\n\n};\n```
['C++']