C++ set solution :)
Approach\n- Go for each possible subarray and push elements into set and before pushing it check if it going to give answer or not or check if it will reduce an
# Approach\n- Go for each possible subarray and push elements into set and before pushing it check if it going to give answer or not or check if it will reduce answer or not  \n\n# Complexity\n- Time complexity: $$O(N* N * logN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N*N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n    int findJustLess(set<int> &se, int val){\n        auto it=se.lower_bound(val);\n        if(it==se.begin()){\n            return -1;\n        }\n        it--;\n        return *it;\n    }\n\n    int findJustGre(set<int> &se, int val){\n        auto it=se.upper_bound(val);\n        if(it==se.end()){\n            return -1;\n        }\n        return *it;\n    }\n\n\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int ans=0;\n\n        for(int i=0;i<nums.size();i++){\n            set<int> se;\n            int prev=0;\n            se.insert(nums[i]);\n            int imbal=0;\n            for(int j=i+1;j<nums.size();j++){\n                if(se.find(nums[j])!=se.end()){\n                    ans+=imbal;\n                    continue;\n                }\n                int less=findJustLess(se,nums[j]);\n                int gre=findJustGre(se,nums[j]);\n\n                if(less!=-1 && gre!=-1 && gre-less>1){\n                    imbal--;\n                }\n                if(gre!=-1 && gre-nums[j]>1){\n                    imbal++;\n                }\n                if(less!=-1 && nums[j]-less>1){\n                    imbal++;\n                }\n    \n                ans+=imbal;\n                se.insert(nums[j]);\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']