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 8e7c7fa commit f26d9cfCopy full SHA for f26d9cf
1395. Count Number of Teams
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ int numTeams(vector<int>& v) {
4
+ int ans = 0, n = v.size();
5
+
6
+ for (int i = 1; i < n-1; i++) {
7
+ int left_smaller = 0, right_greater = 0;
8
9
+ for (int j = 0; j < n; j++) {
10
+ if (j < i && v[j] < v[i])
11
+ left_smaller++;
12
+ else if (j > i && v[j] > v[i])
13
+ right_greater++;
14
+ }
15
16
+ // Counting valid teams in increasing order
17
+ ans += left_smaller * right_greater;
18
19
+ // Counting valid teams in decreasing order
20
+ ans += (i - left_smaller) * (n - i - right_greater - 1);
21
22
23
+ return ans;
24
25
+};
0 commit comments