Python | Super Easy Method | SortedList (Balanced Binary Tree)
Python | Super Easy Method | SortedList (Balanced Binary Tree)\n\n\nfrom sortedcontainers import SortedList\nclass Solution:\n    def findLH(self,B,x):\n       
**Python | Super Easy Method | SortedList (Balanced Binary Tree)**\n\n```\nfrom sortedcontainers import SortedList\nclass Solution:\n    def findLH(self,B,x):\n            \'\'\'\n            Count number of values higher (H) and lower (L) than "x"\n            \'\'\'\n            L =          B.bisect_left (x)\n            H = len(B) - B.bisect_right(x)\n            return L,H\n    def numTeams(self, A):\n        left  = SortedList()\n        right = SortedList(A)\n        res   = 0\n        #\n        for x in A:\n            right.remove(x)\n            #\n            L_left ,H_left  = self.findLH(left ,x)\n            L_right,H_right = self.findLH(right,x)\n            #\n            # Update:    [Nums lower  than "x" to the left] * [Nums higher than "x" to the right]\n            #          + [Nums higher than "x" to the left] * [Nums lower  than "x" to the right]\n            #\n            res            += L_left * H_right + H_left  * L_right\n            #\n            left .add   (x)\n        return res\n```
['Python', 'Python3']