C++ easy understanding|| Binary Search
\nclass Solution {\npublic:\n    int insertInSortedArray(vector<int>& arr, int element) {\n        int low = 0;\n        int high = arr.size() - 1;\n        int
```\nclass Solution {\npublic:\n    int insertInSortedArray(vector<int>& arr, int element) {\n        int low = 0;\n        int high = arr.size() - 1;\n        int mid;\n        while (low <= high) {\n            mid = low + (high - low) / 2;\n\n            if (element == arr[mid]) {\n                arr.insert(arr.begin() + mid + 1, element);\n                return mid + 1;\n            } else if (element < arr[mid]) {\n                high = mid - 1;\n            } else {\n                low = mid + 1;\n            }\n        }\n        arr.insert(arr.begin() + low, element);\n        return low;\n    }\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;i<n;i++){\n            vector<int>arr;\n            arr.push_back(nums[i]);\n            int b=0,cnt=0;\n            for(int j=i+1;j<n;j++){\n                int a=insertInSortedArray(arr,nums[j]);\n                if(a==0){\n                    if(arr[a+1]-arr[a]>1) b++;\n                }else if(a==arr.size()-1){\n                    if(arr[a]-arr[a-1]>1) b++;\n                }else{\n                    if(arr[a+1]-arr[a]>1) b++;\n                    if(arr[a]-arr[a-1]>1) b++;\n                    if(arr[a+1]-arr[a-1]>1)b--;\n                }\n                cnt+=b;\n            }\n            ans+=cnt;\n        }\n        return ans;\n    }\n};\n```
['Array', 'C', 'Sorting', 'Binary Tree']