Skip to content

Commit 11de539

Browse files
committed
Feb 6
1 parent edba1a4 commit 11de539

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| February 03 | [3105. Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray/) | Easy | Solved |
1010
| February 04 | [1800. Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum/) | Easy | Solved |
1111
| February 05 | [1790. Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/) | Easy | Solved |
12-
| February 06 | []() | | |
12+
| February 06 | [1726. Tuple with Same Product](https://leetcode.com/problems/tuple-with-same-product/) | Medium | Solved |
1313
| February 07 | []() | | |
1414
| February 08 | []() | | |
1515
| February 09 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 5 | 5 | 0 |
41-
| Medium | 0 | 0 | 0 |
41+
| Medium | 1 | 1 | 0 |
4242
| Hard | 0 | 0 | 0 |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from itertools import combinations
2+
from typing import List
3+
4+
5+
class Solution:
6+
def tupleSameProduct(self, nums: List[int]) -> int:
7+
product_freq = dict()
8+
count = 0
9+
for a, b in combinations(nums, 2):
10+
product = a * b
11+
if product in product_freq:
12+
count += 8 * product_freq[product]
13+
product_freq[product] += 1
14+
else:
15+
product_freq[product] = 1
16+
return count
17+
18+
19+
def main():
20+
nums = [2, 3, 4, 6]
21+
assert Solution().tupleSameProduct(nums) == 8
22+
23+
nums = [1, 2, 4, 5, 10]
24+
assert Solution().tupleSameProduct(nums) == 16
25+
26+
27+
if __name__ == '__main__':
28+
main()

0 commit comments

Comments
 (0)