Python. O(N^2). set
Solution:\n1. For each i we have a loop j till len(A)\n2. we create a set before second loop and count of irrational numbers\n3. For each element x we have seve
**Solution:**\n1. For each i we have a loop j till len(A)\n2. we create a set before second loop and count of irrational numbers\n3. For each element x we have several options:\n\t- x in seen -> do nothing\n\t- x in between min and max if x + 1 and x - 1 in seen - joing 2 groups (count -=1) if x + 1 and x - 1 not in seen add + 1 else do nothing\n\t- everytime in 2d loop update ans with count\n\n```python\nclass Solution:\n    def sumImbalanceNumbers(self, A: List[int]) -> int:\n        ans = 0\n        for i in range(len(A)):\n            count = 0\n            seen = {A[i]}\n            count = 0\n            for x in A[i+1:]:\n                if x not in seen and (x+1 in seen and x-1 in seen):\n                    # union 2 groups\n                    count -=1\n                elif x not in seen and (x+1 not in seen and x-1 not in seen):\n\t\t\t\t    # add new group\n                    count +=1\n                seen.add(x)\n                ans += count\n        return ans\n```\nTime: `O(N^2)`\nSpace: `O(N)`\n
['Ordered Set', 'Python']