Leetcode 1511 Solution

This article provides solution to leetcode question 1511 (count-number-of-teams)

https://leetcode.com/problems/count-number-of-teams

Solution

class Solution:
    def numTeams(self, rating: List[int]) -> int:
        def count(rating):
            ans = 0

            for i in range(len(rating)):
                down = 0
                up = 0

                for j in range(i):
                    down += int(rating[i] > rating[j])

                for j in range(i + 1, len(rating)):
                    up += int(rating[i] < rating[j])

                ans += down * up
            return ans

        return count(rating) + count(list(reversed(rating)))