Simple Python solution beats 100%
Approach\n Describe your approach to solving the problem. \nFor each element i as the beginning of a subarray, we maintain a value k for the current imbalance n
# Approach\n<!-- Describe your approach to solving the problem. -->\nFor each element `i` as the beginning of a subarray, we maintain a value `k` for the current imbalance number. Decrease `k` when the new element `v` fills the gap between `v - 1` and `v + 1`; increase `k` when the new element `v` creates two gaps in `v - 1` and `v + 1`. Sum up all the `k` values for each `j > i`.  \n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ for the hash table\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        ans = 0\n        n = len(nums)\n        for i in range(n):\n            appears = set([nums[i]])\n            k = 0\n            for j in range(i+1, n):\n                v = nums[j]\n                if v in appears: \n                    pass\n                elif (v - 1) in appears and (v + 1) in appears:\n                    k -= 1\n                elif (v - 1) in appears or (v + 1) in appears:\n                    pass\n                else:\n                    k += 1\n                ans += k\n                appears.add(v)\n        return ans\n```
['Hash Table', 'Python3']