Skip to content

Commit 71a8583

Browse files
committed
Add solution #1726
1 parent aa8633e commit 71a8583

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@
463463
1672|[Richest Customer Wealth](./1672-richest-customer-wealth.js)|Easy|
464464
1679|[Max Number of K-Sum Pairs](./1679-max-number-of-k-sum-pairs.js)|Medium|
465465
1716|[Calculate Money in Leetcode Bank](./1716-calculate-money-in-leetcode-bank.js)|Easy|
466+
1726|[Tuple with Same Product](./1726-tuple-with-same-product.js)|Medium|
466467
1732|[Find the Highest Altitude](./1732-find-the-highest-altitude.js)|Easy|
467468
1748|[Sum of Unique Elements](./1748-sum-of-unique-elements.js)|Easy|
468469
1752|[Check if Array Is Sorted and Rotated](./1752-check-if-array-is-sorted-and-rotated.js)|Easy|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 1726. Tuple with Same Product
3+
* https://leetcode.com/problems/tuple-with-same-product/
4+
* Difficulty: Medium
5+
*
6+
* Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d)
7+
* such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.
8+
*/
9+
10+
/**
11+
* @param {number[]} nums
12+
* @return {number}
13+
*/
14+
var tupleSameProduct = function(nums) {
15+
const map = new Map();
16+
let count = 0;
17+
18+
for (let i = 0; i < nums.length; i++) {
19+
for (let j = i + 1; j < nums.length; j++) {
20+
map.set(nums[i] * nums[j], map.get(nums[i] * nums[j]) + 1 || 1);
21+
}
22+
}
23+
24+
Array.from(map).forEach(([key, value]) => {
25+
count += value > 1 ? value * (value - 1) / 2 : 0;
26+
});
27+
28+
return count * 8;
29+
};

0 commit comments

Comments
 (0)