Python || Dynamic Programming
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\no(n^2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n^2)\n\n# Code\n```python3 []\nclass Solution:\n    def sumImbalanceNumbers(self, nums: List[int]) -> int:\n        ans = 0\n        ln = len(nums)\n        dp = [[0 for _ in range(ln)] for _ in range(ln)]\n        for i in range(ln - 2, -1, -1):\n            temp = nums[i]\n            l, r = None, None\n            for j in range(i + 1, ln):\n                if nums[j] == temp:\n                    r = 0\n                elif nums[j] == temp + 1 and r != 0:\n                    r = 1\n                if l == None and nums[j] == temp - 1:\n                    l = 1\n                dp[i][j] = dp[i + 1][j]\n                if l:\n                    if r:\n                        dp[i][j] -= 1\n                else:\n                    if r == None:\n                        dp[i][j] += 1\n                ans += dp[i][j]\n        return ans\n\n                    \n```
['Array', 'Dynamic Programming', 'Python3']