O(n3) | Easy solution
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int sumImbalanceNumbers(int[] nums) {\n        int ans = 0;\n        int n = nums.length;\n        for(int i = 0; i<n - 1; i++) {\n            int tmp[] = new int[n+1];\n            tmp[nums[i]]++;\n            for(int j = i + 1; j<n; j++) {\n                tmp[nums[j]]++;\n                ans += addImbalance(tmp);\n            }\n        }\n        return ans;\n    }\n   \n    int addImbalance(int[] tmp) {\n        int n = tmp.length;\n        int tmpAns = 0;\n        int fone = 0;\n        int sone = 0;\n        for(int i = 1; i < n; i++) {\n            if(tmp[i] > 0) {\n                if(fone == 0 || i - fone <= 1)  {\n                    fone = i;\n                }\n                else if(i - fone > 1){\n                    tmpAns += (1);\n                    fone = i;\n                }\n            }\n        }\n        return tmpAns;\n    }\n}\n```
['Java']