We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1c1a5eb commit f761ca0Copy full SHA for f761ca0
1396-count-number-of-teams.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {number[]} rating
3
+ * @return {number}
4
+ */
5
+const numTeams = function(rating) {
6
+ let res = 0
7
+ for(let i = 1, n = rating.length; i < n - 1; i++) {
8
+ const less = Array(2).fill(0), greater = Array(2).fill(0)
9
+ for(let j = 0; j < n; j++) {
10
+ if(rating[i] > rating[j]) {
11
+ less[j < i ? 0 : 1]++
12
+ }
13
+ if(rating[i] < rating[j]) {
14
+ greater[j > i ? 0 : 1]++
15
16
17
+ res += less[0] * greater[0] + less[1] * greater[1]
18
19
+ return res
20
+};
0 commit comments