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 0feb780 commit b6173e7Copy full SHA for b6173e7
2552-count-increasing-quadruplets.js
@@ -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