Skip to content

Commit b6173e7

Browse files
authored
Create 2552-count-increasing-quadruplets.js
1 parent 0feb780 commit b6173e7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const countQuadruplets = function(nums) {
6+
const B = new Array(nums.length + 1).fill(0);
7+
let quadruplets = 0;
8+
9+
for (let i = 0; i < nums.length; i += 1) {
10+
let countSmaller = 0;
11+
12+
for (let j = 0; j < i; j += 1) {
13+
if (nums[j] < nums[i]) {
14+
countSmaller += 1;
15+
quadruplets += B[nums[j]];
16+
} else {
17+
// countSmaller is all the As nums[j] is the B, nums[i] is C
18+
// so nums[j] is apart of countSmaller A-B-C relationships with nums[i]
19+
B[nums[j]] += countSmaller;
20+
}
21+
}
22+
}
23+
24+
return quadruplets
25+
};

0 commit comments

Comments
 (0)