🔥Easy & Best C++ Code💯 || Set🌟
Complexity\n- Time complexity:\nO(n ^ 2)\n\n- Space complexity:\nO(n)\n\n# Code\n## Please Upvote if u liked my Solution\uD83E\uDD17\n\nclass Solution {\npublic
# Complexity\n- Time complexity:\nO(n ^ 2)\n\n- Space complexity:\nO(n)\n\n# Code\n## Please Upvote if u liked my Solution\uD83E\uDD17\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int n = nums.size(),sum = 0,prev = 0;\n        set<int> st;\n        for(int i=0;i<n-1;i++){\n            st.insert(nums[i]);\n            prev = 0;\n            for(int j=i+1;j<n;j++){\n                if(st.find(nums[j]) == st.end()){\n                    if(st.find(nums[j] - 1) == st.end() && st.find(nums[j] + 1) == st.end())\n                        prev++;\n                    else if(st.find(nums[j] - 1) != st.end() && st.find(nums[j] + 1) != st.end())\n                        prev--;\n                }\n                sum += prev;\n                st.insert(nums[j]);\n            }\n            st.clear();\n        }\n        return sum;\n    }\n};\n```
['Array', 'Ordered Set', 'C++']