Skip to content

Commit af149e1

Browse files
authored
Merge pull request #1 from Chayandas07/Chayandas07-patch-1
Create 22 nov 22 November Magic Triplets
2 parents bfebd5d + 9012805 commit af149e1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

22 nov 22 November Magic Triplets

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Solution{
2+
public:
3+
int countTriplets(vector<int>arr){
4+
5+
// Code here.
6+
7+
int s=0, e=0, i=0, j=0, p=0, q=0;
8+
9+
int ans=0;
10+
11+
int n =arr.size();
12+
13+
for(i=1;i<n-1;i++){
14+
15+
s=0,e=i+1;
16+
17+
p=0,q=0;
18+
19+
for(j=0;j<i;j++){
20+
21+
if(arr[i]>arr[j]){
22+
23+
p++;
24+
25+
}
26+
27+
}
28+
29+
for(j=i+1;j<n;j++){
30+
31+
if(arr[i]<arr[j]){
32+
33+
q++;
34+
35+
}
36+
37+
}
38+
39+
ans+=p*q;
40+
41+
}
42+
43+
return ans;
44+
45+
}
46+
};

0 commit comments

Comments
 (0)