[Python3] O(N^2) Time, O(N) Space Using a HashSet
Use a hash set to look for "links" or "holes" in continuity\n\n# Code\n\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        an
Use a hash set to look for "links" or "holes" in continuity\n\n# Code\n```\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        ans = 0\n        \n        for i in range(0, len(nums)):\n            seen = set()\n            imb = 0\n            \n            for l in range(i, -1, -1):\n                if seen and nums[l] not in seen: # nonempty, non duplicate\n                    if nums[l] - 1 in seen and nums[l] + 1 in seen: # hole filled\n                        imb -= 1\n                    elif not (nums[l] - 1 in seen or nums[l] + 1 in seen): # new hole\n                        imb += 1\n                \n                seen.add(nums[l])\n                ans += imb\n        \n        return ans\n        \n```
['Python3']