Java O(n^2) and O(N) memory, beats 97%
For every element  e in array \n\t1. For every element b before this where b < e\n          - Coutn number of elements before b and less than b\n    2. For ever
For every element  **e** in array \n\t1. For every element **b** before this where **b < e**\n          - Coutn number of elements before b and less than b\n    2. For every element **b** before this where **b > e**\n          -  Coutn number of elements before b and greather than b\n\n```\npublic int numTeams(int[] rating) {\n\tint[] dp = new int[rating.length];\n\tint[] dp2 = new int[rating.length];\n\tint ans = 0;\n\tfor(int i = 1; i < rating.length; i++){\n\t\tfor(int j = i - 1; j >= 0; j--){\n\t\t\tif(rating[j] < rating[i]){\n\t\t\t\tdp[i]++;\n\t\t\t\tans += dp[j];\n\t\t\t} \n\t\t\tif(rating[j] > rating[i]){\n\t\t\t\tdp2[i]++;\n\t\t\t\tans += dp2[j];\n\t\t\t}\n\t\t}\n\t}\n\treturn ans;\n}\n```\n\t\t\n
[]