question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
maximum-product-of-the-length-of-two-palindromic-subsequences
C++ EASY RECURSION + BACKTRACKING
c-easy-recursion-backtracking-by-the_exp-yrzx
```\nclass Solution {\npublic:\n int ans =-1;\n bool ispal(vector&a)\n {\n int n=a.size();\n for(int i=0;i&s1,vector\&s2,int i)\n {\n
the_expandable
NORMAL
2022-02-28T09:07:24.662365+00:00
2022-02-28T09:07:24.662396+00:00
139
false
```\nclass Solution {\npublic:\n int ans =-1;\n bool ispal(vector<char>&a)\n {\n int n=a.size();\n for(int i=0;i<n/2;i++)\n {\n if(a[i] != a[n-1-i])return false;\n }\n return true;\n }\n void solve(string s,vector<char>&s1,vector<char>&s2,int i)\n {\n ...
1
0
['Backtracking']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
C++ || BITMASK
c-bitmask-by-easy_coder-cm2d
```\nclass Solution {\npublic:\n \n bool isPalindrome(string s){\n if(s.size() == 1) return true;\n string tmp = s;\n reverse(tmp.beg
Easy_coder
NORMAL
2022-01-18T07:33:20.924362+00:00
2022-01-18T07:33:20.924394+00:00
269
false
```\nclass Solution {\npublic:\n \n bool isPalindrome(string s){\n if(s.size() == 1) return true;\n string tmp = s;\n reverse(tmp.begin(),tmp.end());\n return tmp == s;\n }\n \n int maxProduct(string s) {\n int n = s.size();\n map<int,int> mp;\n f...
1
0
['Bit Manipulation', 'C', 'Bitmask']
1
maximum-product-of-the-length-of-two-palindromic-subsequences
Maximum Product of the Length of Two Palindromic Subsequences | C++ | LPS
maximum-product-of-the-length-of-two-pal-kgnp
LPS : Longest Palindromic Subsequence\n\nclass Solution {\npublic:\n int LPS(string& s1) {\n string s2 = s1;\n reverse(s2.begin(), s2.end());\n
renu_apk
NORMAL
2022-01-15T18:15:00.133151+00:00
2022-01-15T18:15:28.271072+00:00
216
false
LPS : Longest Palindromic Subsequence\n```\nclass Solution {\npublic:\n int LPS(string& s1) {\n string s2 = s1;\n reverse(s2.begin(), s2.end());\n \n int n = s1.size();\n int dp[n + 1][n + 1];\n for(int i = 0; i < n; i++) dp[i][0] = 0, dp[0][i] = 0;\n \n for(in...
1
0
[]
1
maximum-product-of-the-length-of-two-palindromic-subsequences
faster than 93.69%, less than 94.86% , C++, simple and concise
faster-than-9369-less-than-9486-c-simple-rqko
\nclass Solution {\npublic:\n int maxProduct(string s) {\n int n=s.size();\n int maskMax=1<<n-1;\n \n int ret=0;\n for(int
zzwolf1306489
NORMAL
2022-01-11T08:38:43.071031+00:00
2022-01-11T08:38:43.071074+00:00
132
false
```\nclass Solution {\npublic:\n int maxProduct(string s) {\n int n=s.size();\n int maskMax=1<<n-1;\n \n int ret=0;\n for(int mask=1;mask<maskMax;mask++){\n string s1,s2;\n for(int i=0;i<s.size();i++){\n if(mask & 1<<i)\n s1+=...
1
0
[]
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Java | Simple | Backtracking
java-simple-backtracking-by-pagalpanda-9xpp
\npublic int maxProduct(String s) {\n solve(s, "", "", 0);\n return ans;\n }\n int ans;\n void solve(String s, String s1, String s2, int
pagalpanda
NORMAL
2021-09-28T01:48:43.278101+00:00
2021-09-28T01:48:43.278132+00:00
370
false
```\npublic int maxProduct(String s) {\n solve(s, "", "", 0);\n return ans;\n }\n int ans;\n void solve(String s, String s1, String s2, int start) {\n if(start == s.length()) {\n if(isPal(s1) && isPal(s2)) {\n int val = s1.length()*s2.length();\n an...
1
0
['Backtracking', 'Java']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
C++ creating all subsets and storing them
c-creating-all-subsets-and-storing-them-93o97
\nclass Solution {\npublic:\n bool isPalindrome(string str){\n int i=0,j = str.length()-1;\n while(i<j){\n if(str[i]!=str[j])return
shvmkj
NORMAL
2021-09-18T10:51:01.937979+00:00
2021-09-18T10:51:01.938013+00:00
149
false
```\nclass Solution {\npublic:\n bool isPalindrome(string str){\n int i=0,j = str.length()-1;\n while(i<j){\n if(str[i]!=str[j])return false;\n i++;\n j--;\n }\n return true;\n }\n int maxProduct(string s) {\n int n = s.length();\n vect...
1
0
[]
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Disjoint subsequence | Bitmasking | dp | c++
disjoint-subsequence-bitmasking-dp-c-by-3m3fl
\nint max_palindrome(string a)\n {\n int n = a.size();\n if(n==0)\n return 0;\n vector<vector<int>> dp(n, vector<int>(n,0));
Dr_Strange_10
NORMAL
2021-09-15T10:25:40.590135+00:00
2021-09-15T10:25:40.590167+00:00
308
false
```\nint max_palindrome(string a)\n {\n int n = a.size();\n if(n==0)\n return 0;\n vector<vector<int>> dp(n, vector<int>(n,0));\n for(int i=0;i<n;i++)\n {\n dp[i][i] = 1;\n }\n\t\t\n\t\t// dist is the distance between i and j pointer...\n for(in...
1
0
['Dynamic Programming', 'Bitmask']
1
maximum-product-of-the-length-of-two-palindromic-subsequences
recursion and bitset
recursion-and-bitset-by-michelusa-ehxd
This approach:\n identify all palindroms\n store found palindroms as a bitset of their character positions in an unordered set\n* enumerate all combinations to
michelusa
NORMAL
2021-09-14T15:15:32.516917+00:00
2021-09-14T15:22:26.369930+00:00
53
false
This approach:\n* identify all palindroms\n* store found palindroms as a bitset of their character positions in an unordered set\n* enumerate all combinations to find the max product (length is how many bits are set)\n\n\nExplaining a bit the recursion: we can either have a character or not in the sequence we are ...
1
0
['C']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
(C++) 2002. Maximum Product of the Length of Two Palindromic Subsequences
c-2002-maximum-product-of-the-length-of-7l36g
\n\nclass Solution {\npublic:\n int maxProduct(string s) {\n int n = s.size(); \n vector<int> dp(1 << n); \n for (int mask = 1; mask < (
qeetcode
NORMAL
2021-09-13T17:58:55.476889+00:00
2021-09-13T18:09:13.031701+00:00
113
false
\n```\nclass Solution {\npublic:\n int maxProduct(string s) {\n int n = s.size(); \n vector<int> dp(1 << n); \n for (int mask = 1; mask < (1 << n); ++mask) \n if ((mask & mask-1) == 0) dp[mask] = 1; \n else {\n int lo = log2(mask & ~(mask-1)), hi = log2(mask)...
1
0
['C']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
[Python3] bitmask dp
python3-bitmask-dp-by-ye15-oqf9
Please check out this commit for solutions of weekly 258. \n\nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n @cache\n def l
ye15
NORMAL
2021-09-13T14:59:14.593590+00:00
2021-09-13T18:13:32.527286+00:00
187
false
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/0de189059bd6af4dabe23d9066dde1655f3334fc) for solutions of weekly 258. \n```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n @cache\n def lps(mask): \n """Return length of longest palindromic seq...
1
0
['Python3']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
NOT 2^n. O(n^2) + O(p^2) where n is length of string and p is number of palindromes
not-2n-on2-op2-where-n-is-length-of-stri-8tup
\n/*\n\tO(n^2) + O(plogp) where p is number of palindromes\n\n\tAlgorithm: for each posible palindrome starting charactera look at each possible palindrome end
justacoder3
NORMAL
2021-09-12T18:14:54.819966+00:00
2021-09-12T20:21:10.539866+00:00
66
false
```\n/*\n\tO(n^2) + O(plogp) where p is number of palindromes\n\n\tAlgorithm: for each posible palindrome starting charactera look at each possible palindrome end character, and if valid, add it\'s length and mask of bits, set corresponding to which positions were used by the palindrome, to a list of palindromes \n\n\t...
1
0
[]
1
maximum-product-of-the-length-of-two-palindromic-subsequences
much faster than bitmask 100ms 100%
much-faster-than-bitmask-100ms-100-by-ak-8dtm
\nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n @lru_cache(None)\n def findBigPalLen(x): #O(n^2)\n if len(x) <=
akbc
NORMAL
2021-09-12T13:59:04.155324+00:00
2021-09-12T14:00:57.177868+00:00
163
false
```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n \n @lru_cache(None)\n def findBigPalLen(x): #O(n^2)\n if len(x) <= 1: return len(x)\n if x[0] == x[-1]: return 2 + findBigPalLen(x[1:-1])\n return max(findBigPalLen(x[1:]), findBigPalLen(x[:-1]))\n ...
1
0
['Python3']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
C++ bottom-up DP mask
c-bottom-up-dp-mask-by-walter01-m7nw
Let dp[mask] denotes the longest length of palindromic subsequence in the string "mask" specifies. For example, mask = "11010", s = "abcad", mask has the sequen
walter01
NORMAL
2021-09-12T08:57:24.144886+00:00
2021-09-12T08:57:24.144915+00:00
42
false
Let dp[mask] denotes the longest length of palindromic subsequence in the string "mask" specifies. For example, mask = "11010", s = "abcad", mask has the sequence of "a, b, a", and dp[mask] = 3; other code is exactly to find the longest length of palindromic. \n\n\n\'\'\'\n\n int maxProduct(string s) {\n\t\t\tin...
1
0
[]
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Python DFS + Memorisation
python-dfs-memorisation-by-jamescandy-kudx
Intuition: similar to LCS, we loop through every possible combination of parlimdromic subsequences, but also introduce two extra parameter, exclude which is the
jamescandy
NORMAL
2021-09-12T05:12:39.993494+00:00
2021-09-12T06:34:55.965147+00:00
261
false
Intuition: similar to LCS, we loop through every possible combination of parlimdromic subsequences, but also introduce two extra parameter, `exclude` which is the indexes of first palindromic subsequences, `num` indicating the number of palindromic subsequences e.g. 0 means first subsequence, 1 means second subsequence...
1
0
['Depth-First Search', 'Python']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Isn't this insane how a small change (pass by reference) allows TLE to become AC
isnt-this-insane-how-a-small-change-pass-k15p
Isn\'t this insane how this small change allows the same solution to pass? Shouldn\'t leetcode be able to discern this is not some major change and allow both?\
ritam777
NORMAL
2021-09-12T04:59:59.395449+00:00
2021-09-12T05:02:11.382068+00:00
128
false
Isn\'t this insane how this small change allows the same solution to pass? Shouldn\'t leetcode be able to discern this is not some major change and allow both?\n\nAccepted\n```\nclass Solution {\npublic:\n int res, n;\n string str;\n bool isPalin(string s, int n) {\n for (int i=0; i<n/2; i++) {\n ...
1
0
[]
0
maximum-product-of-the-length-of-two-palindromic-subsequences
C++ || Check All subsequences
c-check-all-subsequences-by-debo01-25pd
Check All subsequences\nand check their lps.\nthen finally return the max possible ans.\n\nclass Solution {\npublic:\n int ans=1;\n unordered_map<string,i
debo01
NORMAL
2021-09-12T04:47:14.669064+00:00
2021-09-12T04:52:32.264208+00:00
143
false
Check All subsequences\nand check their lps.\nthen finally return the max possible ans.\n```\nclass Solution {\npublic:\n int ans=1;\n unordered_map<string,int>um;\n void func(string s,string x,string y,int i){\n \n if(i==s.length()){\n ans=max(ans,functiontofindlps(x)*functiontofindlp...
1
0
['Backtracking', 'C']
1
maximum-product-of-the-length-of-two-palindromic-subsequences
javascript bitmask brute force 1239ms
javascript-bitmask-brute-force-1239ms-by-4si3
Main idea:\n(1) get all palindrome subsequence\n(2) parse all ways of picking two of them, if disjoint, max the product in result.\n\nconst isPalindrome = (s) =
henrychen222
NORMAL
2021-09-12T04:26:12.997897+00:00
2021-09-12T04:37:48.404352+00:00
316
false
Main idea:\n(1) get all palindrome subsequence\n(2) parse all ways of picking two of them, if disjoint, max the product in result.\n```\nconst isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };\n\nconst maxProduct = (s) => {\n let...
1
0
['Bitmask', 'JavaScript']
1
maximum-product-of-the-length-of-two-palindromic-subsequences
[python] iterative based brute force solution
python-iterative-based-brute-force-solut-w0ay
things to notice :\n1.deep copy\n2. covering every start point\n```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n q= deque()\n for
user4436h
NORMAL
2021-09-12T04:13:20.698886+00:00
2021-09-12T04:45:35.706459+00:00
114
false
things to notice :\n1.deep copy\n2. covering every start point\n```\nclass Solution:\n def maxProduct(self, s: str) -> int:\n q= deque()\n for i in range(len(s)):\n q.append((s[i],[i]))\n ml=0\n n=0\n while q:\n st,li=q.pop()\n if st==st[::-1]:\n ...
1
0
['Iterator', 'Python']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Brute force: Bitmask + Longest Palindromic Subsequence
brute-force-bitmask-longest-palindromic-bw5yi
Generate all possible splits of s into two sequences of minimum 1 character (using bitmask).\nRun the longest palindromic subsequence algorithm on both parts an
prezes
NORMAL
2021-09-12T04:10:35.395984+00:00
2021-09-12T04:13:40.818403+00:00
163
false
Generate all possible splits of s into two sequences of minimum 1 character (using bitmask).\nRun the[ longest palindromic subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) algorithm on both parts and return the max encountered product.\n\n```\nclass Solution {\n public int maxProduct(Stri...
1
0
['Bitmask']
0
maximum-product-of-the-length-of-two-palindromic-subsequences
Java | Backtracking
java-backtracking-by-ashish10comp-fzue
\n\nclass Solution {\n private int maxProduct;\n\n public int maxProduct(String s) {\n maxProduct = 0;\n populateMaxProduct(s, new StringBui
ashish10comp
NORMAL
2021-09-12T04:07:18.257353+00:00
2021-09-12T04:07:18.257392+00:00
164
false
```\n\nclass Solution {\n private int maxProduct;\n\n public int maxProduct(String s) {\n maxProduct = 0;\n populateMaxProduct(s, new StringBuilder(), new StringBuilder(), 0);\n return maxProduct;\n }\n\n private void populateMaxProduct(String s, StringBuilder s1, StringBuilder s2, int ...
1
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++/Java Two Sum O(n * m)
cjava-two-sum-on-m-by-votrubac-hz2s
This looks very similar to Two Sum, and we will use Two Sum: Approach 3.\n\nWe just need to call our function "Two Product" :)\n\n> Update: see below for the op
votrubac
NORMAL
2020-09-06T04:00:32.959731+00:00
2020-09-06T19:26:29.343002+00:00
6,955
false
This looks very similar to Two Sum, and we will use [Two Sum: Approach 3](https://leetcode.com/problems/two-sum/solution/).\n\nWe just need to call our function "Two Product" :)\n\n> Update: see below for the optimized version!\n\n**C++**\n```cpp\nint numTriplets(vector<int>& n1, vector<int>& n2) {\n return accumula...
94
2
[]
9
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ O(MN) with explanation
c-omn-with-explanation-by-lzl124631x-0gmq
See my latest update in repo LeetCode\n\n## Solution 1.\n\nType 1 and Type 2 are symmetrical so we can define a function count(A, B) which returns the count of
lzl124631x
NORMAL
2020-09-06T04:02:39.697855+00:00
2020-09-09T07:15:28.670931+00:00
3,369
false
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1.\n\nType 1 and Type 2 are symmetrical so we can define a function `count(A, B)` which returns the count of the Type 1 triples. The answer is `count(A, B) + count(B, A)`.\n\nFor `count(A, B)`, we can use a `unordered_map<int...
38
1
[]
7
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
python solution
python-solution-by-akaghosting-osfq
\tclass Solution:\n\t\tdef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\t\t\td1 = collections.defaultdict(int)\n\t\t\td2 = collections.defaul
akaghosting
NORMAL
2020-09-06T04:24:16.273455+00:00
2022-07-17T16:10:12.570724+00:00
1,718
false
\tclass Solution:\n\t\tdef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\t\t\td1 = collections.defaultdict(int)\n\t\t\td2 = collections.defaultdict(int)\n\t\t\tres = 0\n\t\t\tfor num1 in nums1:\n\t\t\t\td1[num1 * num1] += 1\n\t\t\tfor num2 in nums2:\n\t\t\t\td2[num2 * num2] += 1 \n\t\t\tfor i i...
19
0
[]
5
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java Simple sort
java-simple-sort-by-hobiter-0q55
An easy way to sort and count:\n1, sort all arrays by non-decreasing order;\n2, for each i, shrink from left and right as j and k, then find each triples\n3, ha
hobiter
NORMAL
2020-09-06T04:02:10.027572+00:00
2020-09-13T20:39:55.335942+00:00
1,624
false
An easy way to sort and count:\n1, sort all arrays by non-decreasing order;\n2, for each i, shrink from left and right as j and k, then find each triples\n3, handle special case for dups, such as[1, 1], [1, 1, 1]\nTime: O(M*N)\nSpace: O(1)\n\n```\nclass Solution {\n public int numTriplets(int[] a, int[] b) {\n ...
15
4
[]
4
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
c++ solution O(n*m) using hash_map
c-solution-onm-using-hash_map-by-dilipsu-8x3m
\n#define ll long long int\nclass Solution {\npublic:\n int find(vector<int>nums1,vector<int>nums2)\n {\n unordered_map<ll,ll>mp;\n for(int
dilipsuthar17
NORMAL
2021-03-01T11:23:02.867305+00:00
2021-03-01T11:23:02.867346+00:00
656
false
```\n#define ll long long int\nclass Solution {\npublic:\n int find(vector<int>nums1,vector<int>nums2)\n {\n unordered_map<ll,ll>mp;\n for(int i=0;i<nums2.size();i++)\n {\n for(int j=i+1;j<nums2.size();j++)\n {\n ll p=(long long)nums2[i]*nums2[j];\n ...
11
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python | Instructions to code | Intuitive
python-instructions-to-code-intuitive-by-bsuj
\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n def is_perf_sqrt(n): \n """\n returns bo
prodcode
NORMAL
2020-09-06T04:05:32.412492+00:00
2020-09-06T04:18:47.924374+00:00
886
false
```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n def is_perf_sqrt(n): \n """\n returns bool if a number is a perfect square\n like 4, 16, 25 --> True\n """\n return int(math.sqrt(n) + 0.5) ** 2 == n\n\n num...
11
0
[]
5
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java solution using sorting. With explanation and comments. 4 ms. Faster than 100%.
java-solution-using-sorting-with-explana-aed1
Sort both arrays.\n2. Similar to the Two sum we have to find all the pairs that matches to the target. Target is the Square number. \n3. Start with left pointer
shaishavjogani
NORMAL
2020-09-06T05:05:43.505364+00:00
2020-09-08T06:20:11.271116+00:00
662
false
1. Sort both arrays.\n2. Similar to the Two sum we have to find all the pairs that matches to the target. Target is the Square number. \n3. Start with left pointer set to 0, and right pointer set to length-1.\n4. Must handle duplicates. \n\t* \te.g. Target: 4, nums = [1,1,4,4]\n\t* \tSo, total 4 pairs with indexes (0,2...
7
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python3 | Using Counter
python3-using-counter-by-tbvho-rsoo
For both nums1 and nums2, aggregate all the squares in nums1 and nums2. We will use this to easily track all occurences of nums1[i] * nums1[j] in nums2 and num
tbvho
NORMAL
2020-09-06T04:14:05.027809+00:00
2020-09-06T04:14:05.027871+00:00
429
false
For both nums1 and nums2, aggregate all the squares in nums1 and nums2. We will use this to easily track all occurences of nums1[i] * nums1[j] in nums2 and nums2[i] * nums2[j] in nums1. Then just use nested loops to generate possible combinations that could be in either frequency table.\n\n\n```\nimport collections\n\...
7
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ | Two Pointer | 100 % faster
c-two-pointer-100-faster-by-csachdeva-50t0
\nclass Solution {\npublic:\n int countTriplet(vector<int>& nums1, vector<int>& nums2) {\n int count = 0, left, right;\n long num1Val, num2Val;
csachdeva
NORMAL
2020-09-06T04:37:44.518554+00:00
2020-09-06T09:03:42.497546+00:00
969
false
```\nclass Solution {\npublic:\n int countTriplet(vector<int>& nums1, vector<int>& nums2) {\n int count = 0, left, right;\n long num1Val, num2Val;\n unordered_map<int, int> freq;\n \n for(int i = 0; i < nums2.size(); i++) freq[nums2[i]]++;\n \n for(int i = 0; i < nums...
6
0
[]
2
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Straightforward solution - brute force with optimized search using set
straightforward-solution-brute-force-wit-5pcz
\nclass Solution {\npublic:\n bool perfectSquare(long long int n) {\n long long int ans = sqrt(n);\n return n == ans*ans;\n }\n \n int
interviewrecipes
NORMAL
2020-09-06T04:04:04.484495+00:00
2020-09-06T04:04:04.484538+00:00
631
false
```\nclass Solution {\npublic:\n bool perfectSquare(long long int n) {\n long long int ans = sqrt(n);\n return n == ans*ans;\n }\n \n int squareRoot(long long int n) {\n int ans = sqrt(n);\n return ans;\n }\n \n int findTriplets(vector<int> a, vector<int> b) {\n i...
6
0
[]
2
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
2 pointer approach || O(1) space complexity || 98% faster
2-pointer-approach-o1-space-complexity-9-n4s9
\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n Arrays.sort(nums1);\n Arrays.sort(nums2);\n return count(nums1
harshitgoel1110
NORMAL
2021-06-26T13:08:12.317898+00:00
2021-06-26T13:08:12.317941+00:00
469
false
```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n Arrays.sort(nums1);\n Arrays.sort(nums2);\n return count(nums1 , nums2) + count(nums2 , nums1);\n }\n \n public int count(int a[] , int b[]){\n int n = a.length;\n int m = b.length;\n int c...
5
1
['Two Pointers', 'Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++||Two Pointers||Easy to Understand
ctwo-pointerseasy-to-understand-by-retur-cnxx
```\nclass Solution {\npublic:\n int countTriplet(vector &nums1,vector &nums2)\n {\n int ans=0,left,right;\n unordered_map freq;\n fo
return_7
NORMAL
2022-09-04T20:48:27.635595+00:00
2022-09-04T20:48:27.635641+00:00
663
false
```\nclass Solution {\npublic:\n int countTriplet(vector<int> &nums1,vector<int> &nums2)\n {\n int ans=0,left,right;\n unordered_map<int,int> freq;\n for(auto &n:nums2)\n {\n freq[n]++;\n }\n for(int i=0;i<nums1.size();i++)\n {\n long long t=(...
4
0
['Two Pointers', 'C']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++, 20ms, 12MB, max(O(n1+n2), O(d1*d2)) (d1, d2 are number of distinct numbers in nums1 and nums2)
c-20ms-12mb-maxon1n2-od1d2-d1-d2-are-num-jv7q
Firstly we count how many times each number appeared in each vector.\n\nFor each distinct number n1 in one set, we try to find in the other set:\n 1. n2 == n1
alvin-777
NORMAL
2020-09-06T05:27:06.510237+00:00
2020-09-06T06:32:50.219446+00:00
601
false
Firstly we count how many times each number appeared in each vector.\n\nFor each distinct number n1 in one set, we try to find in the other set:\n 1. `n2 == n1` and n2 appeared at least twice\n 2. `n2 < n1` and exists n2x that `n2*n2x == n1*n1` => `n2x == n1*n1/n2`\n\nFor `1`, if n1 appeared f1 times and n2 appeared ...
4
1
['C']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
5 LINE JAVA SOLUTION USING HASHMAP WITH EXPLANATION
5-line-java-solution-using-hashmap-with-zh5ux
1. Store the value of num1*num1 from the first Array in a map.\n2. Using two for loops generate all possible combination of num2 and check if the set contains t
visnunathan
NORMAL
2020-09-06T04:38:18.290999+00:00
2020-09-06T06:36:24.865667+00:00
444
false
**1. Store the value of num1*num1 from the first Array in a map.\n2. Using two for loops generate all possible combination of num2 and check if the set contains those value.\n3. If it contains add it to the sum and return it.**\n```\npublic int calculate(int[] num1, int[] num2) {\n HashMap<Long, Integer> map = n...
4
1
['Java']
2
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ code using unordered_map
c-code-using-unordered_map-by-shalinipan-j93h
\nclass Solution {\npublic:\n int get(vector<int>& nums1, vector<int>& nums2)\n {\n unordered_map<long long int,long long int>m;int ans=0;\n
shalinipandey1955
NORMAL
2020-09-06T06:41:04.916228+00:00
2020-10-26T10:29:34.139047+00:00
158
false
```\nclass Solution {\npublic:\n int get(vector<int>& nums1, vector<int>& nums2)\n {\n unordered_map<long long int,long long int>m;int ans=0;\n for(int i=0;i<nums1.size();i++)\n {\n m[(long long )nums1[i]*nums1[i]]++;\n }\n for(int i=0;i<nums2.size();i++)\n {\n...
3
1
['C']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[C++] Explanation, Approach and Code and Time Complexity
c-explanation-approach-and-code-and-time-80n5
Approach\n 0. Sort the arrays since you need to search\n For type 1:\n\t\n 1. select first number from nums1\n 2. Square it\n 3. Select number fr
rahulanandyadav2000
NORMAL
2020-09-06T04:13:10.557620+00:00
2020-09-06T04:33:27.322417+00:00
474
false
Approach\n 0. Sort the arrays since you need to search\n For type 1:\n\t\n 1. select first number from nums1\n 2. Square it\n 3. Select number from nums2 and divide it by square of nums1[i]\n 4. If divisible, search for all occurences of the other pair in nums2\n 5. Lets there be x occurences then ...
3
0
['C', 'Binary Tree']
2
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Rust || Simple solution
rust-simple-solution-by-user7454af-aql2
Complexity\n- Time complexity: O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n^2)\n Add your space complexity here, e.g. O(n) \n\n
user7454af
NORMAL
2024-06-06T17:09:17.135202+00:00
2024-06-06T17:09:17.135238+00:00
29
false
# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nuse std::collections::HashMap;\nimpl Solution {\n pub fn num_triplets(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {...
2
0
['Rust']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Python 3] O(MN) short and concise
python-3-omn-short-and-concise-by-gabhay-bogn
\tclass Solution:\n\t\tdef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\t\t\tdef get_res(a,b):\n\t\t\t\tres,n=0,len(b)\n\t\t\t\tprod=Counter(
gabhay
NORMAL
2022-07-22T05:06:43.091470+00:00
2022-07-22T05:06:43.091508+00:00
295
false
\tclass Solution:\n\t\tdef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\t\t\tdef get_res(a,b):\n\t\t\t\tres,n=0,len(b)\n\t\t\t\tprod=Counter([x*x for x in a])\n\t\t\t\tfor i in range(n):\n\t\t\t\t\tfor j in range(i+1,n):\n\t\t\t\t\t\tres+=prod[b[i]*b[j]]\n\t\t\t\treturn res\n\t\t\treturn get_res(nums...
2
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Brute force approach | C++
brute-force-approach-c-by-tusharbhart-ifn5
\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n \n unordered_map<long, int> m1, m2;\n for(int
TusharBhart
NORMAL
2022-02-28T08:25:12.432454+00:00
2022-02-28T08:25:12.432484+00:00
271
false
```\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n \n unordered_map<long, int> m1, m2;\n for(int i : nums1) m1[(long long)i*i]++;\n for(int i : nums2) m2[(long long)i*i]++;\n \n int ans = 0;\n \n for(int i=0; i<nums2.si...
2
0
['C']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python intuitive hashmap solution, O(n*m) time
python-intuitive-hashmap-solution-onm-ti-cpqi
\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n sqr1, sqr2 = defaultdict(int), defaultdict(int)\n m, n
byuns9334
NORMAL
2021-12-31T09:31:31.364955+00:00
2021-12-31T09:31:31.364991+00:00
419
false
```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n sqr1, sqr2 = defaultdict(int), defaultdict(int)\n m, n = len(nums1), len(nums2)\n for i in range(m):\n sqr1[nums1[i]**2] += 1\n for j in range(n):\n sqr2[nums2[j]**2] += 1\n ...
2
0
['Python', 'Python3']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C+ (A very simple Two Sum like approach)
c-a-very-simple-two-sum-like-approach-by-5psp
\n//Approach-1 (Simple solution)\nclass Solution {\npublic:\n void twoProduct(ull target, vector<int> & nums, int &count) {\n unordered_map<int, int>
mazhar_mik
NORMAL
2021-06-30T02:05:48.952274+00:00
2021-06-30T02:22:11.825408+00:00
276
false
```\n//Approach-1 (Simple solution)\nclass Solution {\npublic:\n void twoProduct(ull target, vector<int> & nums, int &count) {\n unordered_map<int, int> mp;\n mp[1] = 0;\n for(int i = 0; i<nums.size(); i++) {\n if(target%nums[i] == 0) {\n int remain= target/nums[i];\n ...
2
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
JavaScript Solution
javascript-solution-by-deadication-tzn9
\nvar numTriplets = function(nums1, nums2) {\n const squaredFreq1 = countSquareFreq(nums1);\n const squaredFreq2 = countSquareFreq(nums2);\n \n retu
Deadication
NORMAL
2021-04-26T16:48:27.417270+00:00
2021-04-26T16:55:12.777276+00:00
140
false
```\nvar numTriplets = function(nums1, nums2) {\n const squaredFreq1 = countSquareFreq(nums1);\n const squaredFreq2 = countSquareFreq(nums2);\n \n return countProdFreq(nums1, squaredFreq2) + countProdFreq(nums2, squaredFreq1);\n\t\n \n function countSquareFreq(nums) {\n const freq = new Map();\...
2
0
['Hash Table', 'JavaScript']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java O(n * sqrt(n)) solution using prime factorisation
java-on-sqrtn-solution-using-prime-facto-khkc
Take the example \nnums1 -> [4]\nnums2 -> [2,2,2,4,4,8,8]\nfor the SqrNo = 16, possible 2 pairs of factors are (1,16) (2,8) (4,4)\nHave a count hashmap of all c
tywin_lannister97
NORMAL
2021-03-14T16:54:01.930850+00:00
2021-03-14T16:54:01.930887+00:00
188
false
Take the example \nnums1 -> [4]\nnums2 -> [2,2,2,4,4,8,8]\nfor the SqrNo = 16, possible 2 pairs of factors are (1,16) (2,8) (4,4)\nHave a count hashmap of all count nos and simply check for all these cases. Repeat the same for each of nums2 combination against num1. One edge case is int overflow if n= 10^5 n ^ 2 will c...
2
2
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
93%/91% Python3, Hash table
9391-python3-hash-table-by-awong05-b49z
\nfrom collections import Counter\n\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n def helper(A, B):\n
awong05
NORMAL
2020-09-17T13:17:44.056126+00:00
2020-09-17T13:17:44.056162+00:00
160
false
```\nfrom collections import Counter\n\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n def helper(A, B):\n ans = 0\n C = Counter([a*a for a in A])\n D = Counter()\n for b in B:\n for k, v in D.items():\n ...
2
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Python] Using counter O(n*m)
python-using-counter-onm-by-carloscerlir-0xay
\n def numTriplets(self, A: List[int], B: List[int]) -> int:\n def getTriplets(A, B):\n m, n = len(A), len(B)\n ans = 0\n
carloscerlira
NORMAL
2020-09-06T04:07:13.144072+00:00
2020-09-06T04:20:32.859520+00:00
151
false
```\n def numTriplets(self, A: List[int], B: List[int]) -> int:\n def getTriplets(A, B):\n m, n = len(A), len(B)\n ans = 0\n counter = Counter()\n for j in range(n):\n for k in range(j+1,n):\n prod = B[j]*B[k]\n c...
2
0
['Python']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Java] Use Hashmap to Maintain Frequencies O(N^2 + M^2)
java-use-hashmap-to-maintain-frequencies-zgwa
\n public int numTriplets(int[] nums1, int[] nums2) {\n HashMap<Long, Integer> s1 = new HashMap();\n HashMap<Long, Integer> s2 = new HashMap();
yuhwu
NORMAL
2020-09-06T04:06:37.134275+00:00
2020-09-06T04:06:37.134341+00:00
141
false
```\n public int numTriplets(int[] nums1, int[] nums2) {\n HashMap<Long, Integer> s1 = new HashMap();\n HashMap<Long, Integer> s2 = new HashMap();\n int n1 = nums1.length;\n int n2 = nums2.length;\n for(int i=0; i<n1; i++){\n for(int j=i+1; j<n1; j++){\n l...
2
1
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ Easy 3 Sum, 2 pointer (with comments) | O(N*M) time O(1) space
c-easy-3-sum-2-pointer-with-comments-onm-0y1u
\n\nclass Solution {\npublic:\n #define ll long long\n \n\t// returns count of valids triplets (i, j, K) of type 1\n\t// note that to find of type 2, just
chwanshu27
NORMAL
2020-09-06T04:04:49.667232+00:00
2020-09-06T04:24:55.401567+00:00
172
false
```\n\nclass Solution {\npublic:\n #define ll long long\n \n\t// returns count of valids triplets (i, j, K) of type 1\n\t// note that to find of type 2, just swap nums1 and nums2 while calling \n int returnCount(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size(), m = nums2.size();\n ...
2
0
['Two Pointers', 'C']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python3 Solution
python3-solution-by-deleted_user-k82m
python\ndef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\trev, n1, n2 = 0, Counter(nums1), Counter(nums2)\n\n\tfor i in range(len(nums1)-1):\
deleted_user
NORMAL
2020-09-06T04:02:50.377735+00:00
2020-09-06T04:02:50.377837+00:00
376
false
```python\ndef numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n\trev, n1, n2 = 0, Counter(nums1), Counter(nums2)\n\n\tfor i in range(len(nums1)-1):\n\t\tfor j in range(i+1, len(nums1)):\n\t\t\tt = (nums1[i] * nums1[j])**(1/2)\n\n\t\t\tif t == int(t) and t in n2:\n\t\t\t\trev += n2[t]\n\n\tfor i in range(...
2
0
['Python', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Easy Java Solution Using HashMap
easy-java-solution-using-hashmap-by-ravi-0faf
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ravikumar50
NORMAL
2023-08-05T10:55:36.027232+00:00
2023-08-05T10:55:36.027260+00:00
34
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ || Easy Explanation ||O(N^2)
c-easy-explanation-on2-by-avi1273619-i2r7
// long long temp,t,help are used to keep the product within limits (prevent overflow)\n \n// The idea is to store all the squares in a map(not se
avi1273619
NORMAL
2022-08-06T13:39:36.526555+00:00
2023-01-15T12:45:32.302121+00:00
379
false
// long long temp,t,help are used to keep the product within limits (prevent overflow)\n \n// The idea is to store all the squares in a map(not set because duplicates may be present an dnot even multiset because we won\'t get the number of times the duplicates appears)\n \n// Use nested loo...
1
0
['C']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Javascript] Two Approaches - Hashmap & Two Pointers
javascript-two-approaches-hashmap-two-po-3yp6
Solution 1: Hashmap\n\nThis approach is similar to the two sum problem.\nWe use a hashmap to keep track of the frequencies of past numbers.\nCount the number of
anna-hcj
NORMAL
2022-06-27T10:59:14.335469+00:00
2022-06-27T10:59:14.335512+00:00
142
false
**Solution 1: Hashmap**\n\nThis approach is similar to the two sum problem.\nWe use a hashmap to keep track of the frequencies of past numbers.\nCount the number of `target / nums2[j]` in the hashmap.\n\n`n = length of nums1`, `m = length of nums2`\nTime Complexity: `O(nm)` 498ms\nSpace Complexity: `O(n + m)` 48.3MB\n`...
1
0
['JavaScript']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
python soln
python-soln-by-kumarambuj-6fg5
\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n hash1=defaultdict(int)\n hash2=defaultdict(int)\n
kumarambuj
NORMAL
2022-01-02T08:57:32.870500+00:00
2022-01-02T08:57:32.870530+00:00
114
false
```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n hash1=defaultdict(int)\n hash2=defaultdict(int)\n \n for x in nums1:\n hash1[x*x]+=1\n \n for x in nums2:\n hash2[x*x]+=1\n \n res=0\n for i ...
1
0
['Python']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ Brute force | Using Hash_map
c-brute-force-using-hash_map-by-nitink_3-34c4
\n#define ll long long int\nclass Solution {\npublic:\n \n int find(vector<int>nums1,vector<int>nums2)\n {\n unordered_map<ll,ll>mp;\n //
HustlerNitin
NORMAL
2022-01-01T18:03:06.428556+00:00
2022-01-01T18:03:06.428602+00:00
392
false
```\n#define ll long long int\nclass Solution {\npublic:\n \n int find(vector<int>nums1,vector<int>nums2)\n {\n unordered_map<ll,ll>mp;\n // O(n^2)\n for(int i=0;i<nums2.size();i++)\n {\n for(int j=i+1;j<nums2.size();j++)\n {\n ll p=(long long)nu...
1
0
['C', 'C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ BRUTEFORCE
c-bruteforce-by-the_expandable-p63f
```\nclass Solution {\npublic:\n #define ll long long int\n int numTriplets(vector& a, vector& b) {\n mapmp1;\n mapmp2;\n sort(a.begi
the_expandable
NORMAL
2021-09-23T04:57:11.768427+00:00
2021-09-23T04:57:11.768472+00:00
74
false
```\nclass Solution {\npublic:\n #define ll long long int\n int numTriplets(vector<int>& a, vector<int>& b) {\n map<ll,ll>mp1;\n map<ll,ll>mp2;\n sort(a.begin(),a.end());\n sort(b.begin(),b.end());\n for(int i = 0 ; i < a.size();i++)\n {\n ll p = (ll)a[i]*a[i];...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java solution
java-solution-by-keerthy0212-v0md
\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n return res(nums1,nums2)+res(nums2,nums1);\n }\n public static int res(i
keerthy0212
NORMAL
2021-05-09T17:08:20.012478+00:00
2021-05-09T17:08:20.012519+00:00
255
false
```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n return res(nums1,nums2)+res(nums2,nums1);\n }\n public static int res(int[] nums1,int[] nums2)\n {\n int count=0;\n\t\tHashMap<Long,Integer> map=new HashMap<Long,Integer>();\n\t\tfor(long i:nums1)\n\t\t\tmap.put((i*i),...
1
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python O(n^2) function
python-on2-function-by-dev-josh-b9jy
How do we approach such a question?\n You can try the brute force, but it will TLE\n I always try to fall back to the Two Sum problem\n\t Can we build dictionar
dev-josh
NORMAL
2021-02-16T19:02:26.161304+00:00
2021-02-16T19:11:19.360665+00:00
249
false
* How do we approach such a question?\n* You can try the brute force, but it will TLE\n* I always try to fall back to the **Two Sum problem**\n\t* Can we build dictionaries in linear or n^2 time to avoid n^3 time?\n\t\t* We can count the number of `nums1[i]^2` for example\n\t\t* We can also count the number of `nums2[j...
1
0
['Python', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Python] Count, beats 100%, O(n * m)
python-count-beats-100-on-m-by-shoomoon-2jot
First count the elements in each array, then find the number of triplets for each element.\nIt is faster if there are lots of duplicates.\n\nclass Solution(obje
shoomoon
NORMAL
2021-01-28T18:22:59.641677+00:00
2021-01-28T18:22:59.641714+00:00
148
false
First count the elements in each array, then find the number of triplets for each element.\nIt is faster if there are lots of duplicates.\n```\nclass Solution(object):\n def numTriplets(self, nums1, nums2):\n """\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n """...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python Solution Based on Binary Search And Memorization
python-solution-based-on-binary-search-a-ku2z
Time Complexity = O ( N * N * Log N )\n\n\n\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int: \n nums1.sort()\
pochy
NORMAL
2020-09-08T04:53:10.281496+00:00
2020-09-08T04:57:41.853257+00:00
184
false
Time Complexity = O ( N * N * Log N )\n\n\n```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int: \n nums1.sort()\n nums2.sort()\n \n def lowerbound(target, left, right, nums):\n while left < right:\n mid = left + (right - l...
1
0
['Memoization', 'Binary Tree', 'Python', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python3 3 liner - Number of Ways Where Square of Number Is Equal to Product of Two Numbers
python3-3-liner-number-of-ways-where-squ-67gh
\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n sq1 = Counter(map(mul, nums1, nums1))\n sq2 = Counter(m
r0bertz
NORMAL
2020-09-08T03:20:50.283602+00:00
2020-09-08T03:20:50.283656+00:00
166
false
```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n sq1 = Counter(map(mul, nums1, nums1))\n sq2 = Counter(map(mul, nums2, nums2))\n return sum(sq2[a * b] for a, b in combinations(nums1, 2)) + sum(sq1[a * b] for a, b in combinations(nums2, 2))\n```
1
0
['Python', 'Python3']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java factorization solution O(n + m)
java-factorization-solution-on-m-by-igor-u92m
Algorithm:\n1. Create a map key: (num * num), value: count basing on first array\n2. Go throug the second array, for every number calculate a key containing fa
igor84
NORMAL
2020-09-07T14:24:28.135348+00:00
2020-09-07T15:58:39.652374+00:00
180
false
Algorithm:\n1. Create a map key: (num * num), value: count basing on first array\n2. Go throug the second array, for every number calculate a key containing factors that are represented odd number of times in number. For example, 60 is 2 * 2 * 3 * 5, the key is "3,5"\n3. Search for the values with the same key process...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++|| O(MN)||Easiest solution with self explanatory code
c-omneasiest-solution-with-self-explanat-fe11
Please Note that time complexity of find function in unordered_map is O(1)\n\nclass Solution {\npublic:\n int numTriplets(vector<int>& n1, vector<int>& n2) {
tejpratapp468
NORMAL
2020-09-07T05:56:06.468623+00:00
2020-09-07T05:58:59.159634+00:00
79
false
Please Note that time complexity of find function in unordered_map is O(1)\n```\nclass Solution {\npublic:\n int numTriplets(vector<int>& n1, vector<int>& n2) {\n int n=n1.size();int m=n2.size();\n long ans=0;\n //type 1\n for(int i=0;i<n;i++)\n {\n double a=n1[i];\n ...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C# solution using Dictionary
c-solution-using-dictionary-by-pykan-g1du
\npublic int NumTriplets(int[] nums1, int[] nums2) {\n int w1 = GetWays(nums1, nums2);\n int w2 = GetWays(nums2, nums1);\n return w1 + w2;\
pykan
NORMAL
2020-09-06T09:13:30.698743+00:00
2020-09-11T13:48:20.834182+00:00
72
false
```\npublic int NumTriplets(int[] nums1, int[] nums2) {\n int w1 = GetWays(nums1, nums2);\n int w2 = GetWays(nums2, nums1);\n return w1 + w2;\n }\n \n public int GetWays(int[] nums1, int[] nums2) {\n int numWays = 0;\n long product = 0;\n \n Dictionary<long, int...
1
0
[]
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java Two Diff Solutions O(m^2+n^2) and O(m*n)
java-two-diff-solutions-om2n2-and-omn-by-gwdl
Method1: \n1. Use two different hashmaps\n2. Add entried to map for diff combinations of product\n3. Iterate over arrays and check if square of num exists in ot
meg20
NORMAL
2020-09-06T09:04:43.618580+00:00
2020-09-06T11:29:25.121585+00:00
116
false
Method1: \n1. Use two different hashmaps\n2. Add entried to map for diff combinations of product\n3. Iterate over arrays and check if square of num exists in other map\n\nTime: O(m^2 + n^2)\n```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n Map<Long, Integer> productSet1 = new HashM...
1
1
['Sorting', 'Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java Bruteforce O(N^2)
java-bruteforce-on2-by-janap-fxi9
```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n return getCount(nums1, getMap(nums2)) + getCount(nums2, getMap(nums1));\n
janap
NORMAL
2020-09-06T07:10:18.468508+00:00
2020-09-06T07:10:18.468564+00:00
43
false
```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n return getCount(nums1, getMap(nums2)) + getCount(nums2, getMap(nums1));\n }\n \n Map<Long, Integer> getMap(int[] nums){\n Map<Long, Integer> map = new HashMap<>();\n for(long num: nums)\n map.put(num...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
c++ code using hashmap
c-code-using-hashmap-by-srjohn-312s
\nclass Solution {\npublic:\n unordered_map<double,int> hash1;\n unordered_map<double,int> hash2;\n int numTriplets(vector<int>& nums1, vector<int>& nu
srjohn
NORMAL
2020-09-06T06:56:50.249655+00:00
2020-09-06T06:56:50.249692+00:00
68
false
```\nclass Solution {\npublic:\n unordered_map<double,int> hash1;\n unordered_map<double,int> hash2;\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n for(int i=0;i<nums1.size();i++)\n {if(hash1.find(nums1[i])==hash1.end()) hash1[nums1[i]]=1;\n else hash1[nums1[i]]++; \n ...
1
1
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ using 2 unordered_map
c-using-2-unordered_map-by-tejasrai-qvjx
\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n uno
tejasrai
NORMAL
2020-09-06T06:18:00.064114+00:00
2020-09-06T06:19:30.796917+00:00
39
false
```\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n unordered_map<long long int,long long int>s1;\n unordered_map<long long int,long long int>s2;\n int count=0;\n for(int i=0;i<n;i++)\n ...
1
1
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Why 91/92 TCs passed? Please suggest/help.
why-9192-tcs-passed-please-suggesthelp-b-n7nh
\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n Arrays.sort(nums1);\n Arrays.sort(nums2);\n \n int ans
vvbhandare
NORMAL
2020-09-06T04:19:38.592012+00:00
2020-09-06T04:30:04.838119+00:00
155
false
```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n Arrays.sort(nums1);\n Arrays.sort(nums2);\n \n int ans = 0;\n int n1 = nums1.length, n2 = nums2.length;\n Map<Long, Integer> S1 = new HashMap<>();\n Map<Long, Integer> S2 = new HashMap<>();\n...
1
0
['Sorting']
2
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Easy Python Solution with proper and easy explanation
easy-python-solution-with-proper-and-eas-wlev
Okay so I followed a really simple stragegy:\nI created 2 dictionaries and put up the squared values of all the numbers in both the nums array in seperate dicti
shubhitt
NORMAL
2020-09-06T04:10:51.851297+00:00
2020-09-06T04:10:51.851332+00:00
59
false
Okay so I followed a really simple stragegy:\nI created 2 dictionaries and put up the squared values of all the numbers in both the nums array in seperate dictionaries, with their count\nNow I traverse both the arrays seperately and find out pairs such that, if the pair product is in the opposite dictionary, i.e, if I ...
1
1
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java Solution Using HashMap
java-solution-using-hashmap-by-jjy_yang-lrtr
Attention: Need to change type to Long\n\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n int re=0;\n Map<Long,Integer>
jjy_yang
NORMAL
2020-09-06T04:07:08.933471+00:00
2020-09-06T04:07:08.933515+00:00
65
false
Attention: Need to change type to Long\n```\nclass Solution {\n public int numTriplets(int[] nums1, int[] nums2) {\n int re=0;\n Map<Long,Integer> map=new HashMap<>();\n for(int i:nums1){\n long l=(long)i*(long)i;\n int count=map.getOrDefault(l,0);\n map.put(l,co...
1
1
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[C++] 30s. Faster than 100%
c-30s-faster-than-100-by-subbuffer-2mkh
Sort first, and then check whether the 3 numbers can exist accoriding to the condition. For this purpose, we can use a HashMap to expedite the search. Thus, in
SubBuffer
NORMAL
2020-09-06T04:05:13.729730+00:00
2020-09-06T06:52:19.933729+00:00
168
false
Sort first, and then check whether the 3 numbers can exist accoriding to the condition. For this purpose, we can use a HashMap to expedite the search. Thus, in the beginning, we insert the elements into the HashMap (in C++ ```unordered_map```) and then check for the obvious relationship of ```nums1[i]^2 = nums2[j] * nu...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python, Hashmap
python-hashmap-by-yseeker-6plc
\nclass Solution(object):\n def numTriplets(self, nums1, nums2):\n\n cnt = 0\n a = collections.defaultdict(int)\n b = collections.defaul
yseeker
NORMAL
2020-09-06T04:03:58.069536+00:00
2020-09-06T04:03:58.069583+00:00
230
false
```\nclass Solution(object):\n def numTriplets(self, nums1, nums2):\n\n cnt = 0\n a = collections.defaultdict(int)\n b = collections.defaultdict(int)\n \n for num in nums1:\n a[num*num] += 1\n \n for num in nums2:\n b[num*num] += 1\n \...
1
0
['Python']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
[Python3] frequency table
python3-frequency-table-by-ye15-lsvk
\n\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n cnt1, cnt2 = Counter(nums1), Counter(nums2)\n \n
ye15
NORMAL
2020-09-06T04:02:49.554518+00:00
2020-09-06T04:02:49.554579+00:00
205
false
\n```\nclass Solution:\n def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n cnt1, cnt2 = Counter(nums1), Counter(nums2)\n \n def fn(x, y, freq): \n """Return count of triplet of nums[i]**2 = nums[j]*nums[k]."""\n ans = 0\n for xx in x: \n ...
1
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Straightforward O(N^2) Java Solution with 2 HashMaps
straightforward-on2-java-solution-with-2-h595
\n public int numTriplets(int[] nums1, int[] nums2) {\n //hashMap: product -> freq\n HashMap<Long, Integer> map1 = new HashMap<>();\n Ha
billtang123
NORMAL
2020-09-06T04:02:11.789400+00:00
2020-09-06T04:02:11.789450+00:00
162
false
```\n public int numTriplets(int[] nums1, int[] nums2) {\n //hashMap: product -> freq\n HashMap<Long, Integer> map1 = new HashMap<>();\n HashMap<Long, Integer> map2 = new HashMap<>();\n int n1 = nums1.length;\n int n2 = nums2.length;\n for(int i=0;i<n1; i++){\n fo...
1
0
[]
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Hard Way to solve, but constraints are small
hard-way-to-solve-but-constraints-are-sm-sdoc
IntuitionНужно посчитать тройки, где квадрат одного элемента из одного массива равен произведению двух элементов из другого. Это условие проверяется по всем воз
bezzerli
NORMAL
2025-04-08T00:47:10.023237+00:00
2025-04-08T00:47:10.023237+00:00
2
false
### Intuition Нужно посчитать тройки, где квадрат одного элемента из одного массива равен произведению двух элементов из другого. Это условие проверяется по всем возможным парам. ### Approach 1. Посчитаем частоты квадратов всех элементов `nums1` и `nums2` (храним в словарях). 2. Для всех пар в `nums2`, проверим, есть ...
0
0
['Array', 'Hash Table', 'Math', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
easy solution
easy-solution-by-owenwu4-q6wd
Intuitionprecompute squared freuencies using a hashmapApproachComplexity Time complexity: Space complexity: Code
owenwu4
NORMAL
2025-04-07T21:27:46.922644+00:00
2025-04-07T21:27:46.922644+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> precompute squared freuencies using a hashmap # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your spac...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python, Hashing, Brute Force
python-hashing-brute-force-by-mickeyhao-n5x6
Intuition & ApproachPrecalculate the square of numbers in both lists, and store the frequency. Then iterate through both lists to see if the product of nums2[j]
MickeyHao
NORMAL
2025-01-13T19:27:38.258977+00:00
2025-01-13T19:27:38.258977+00:00
12
false
# Intuition & Approach Precalculate the square of numbers in both lists, and store the frequency. Then iterate through both lists to see if the product of `nums2[j]*nums2[k]` is in the frequency table of `nums1`. Do the same to the other list. # Complexity - Time complexity: $O(N^2)$ - Space complexity: $O(N)$ # Co...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
1577. Number of Ways Where Square of Number Is Equal to Product of Two Numbers
1577-number-of-ways-where-square-of-numb-cai4
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-13T16:52:31.716673+00:00
2025-01-13T16:52:31.716673+00:00
12
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Simple | Intuitive
simple-intuitive-by-richardleee-147y
IntuitionApproachComplexity Time complexity: Space complexity: Code
RichardLeee
NORMAL
2025-01-12T16:10:50.356357+00:00
2025-01-12T16:10:50.356357+00:00
11
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ O(NM) Time, O(1) Auxiliary space, beat 95% runtime solution w/ Detailed explanation
c-onm-time-o1-auxiliary-space-beat-95-ru-hhz7
Intuition\nJust considering a single type (where nums1 is the "target" and nums2 is the "combinations" vector). We may make a few observations:\n\nObservations:
nicklai
NORMAL
2024-11-04T08:20:57.500917+00:00
2024-11-04T08:20:57.500949+00:00
16
false
# Intuition\nJust considering a single type (where nums1 is the "target" and nums2 is the "combinations" vector). We may make a few observations:\n\nObservations:\n- The values of the numbers are **non-negative**, limited to the range 1~100,000\n - If we deal with **sorted** nums1 and nums2, we can we can do some le...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Very intuitive solution using dictionary
very-intuitive-solution-using-dictionary-xpd2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
belka
NORMAL
2024-10-28T19:39:32.897017+00:00
2024-10-28T19:39:32.897041+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Easy simple code || Beats 90|| O(M*N)|| O(M+N)
easy-simple-code-beats-90-omn-omn-by-sum-s1t6
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
sumanth2328
NORMAL
2024-10-15T04:16:15.661749+00:00
2024-10-15T04:16:15.661780+00:00
24
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Array', 'Hash Table', 'Math', 'Counting', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ Solution || Using Maps
c-solution-using-maps-by-vaibhav_arya007-8ba1
Code\ncpp []\nclass Solution {\n // Function to count the number of valid triplets where square of a number from `A`\n // is equal to the product of two n
Vaibhav_Arya007
NORMAL
2024-10-03T22:04:54.421323+00:00
2024-10-03T22:04:54.421347+00:00
24
false
# Code\n```cpp []\nclass Solution {\n // Function to count the number of valid triplets where square of a number from `A`\n // is equal to the product of two numbers from `B`\n int count(vector<int> &A, vector<int> &B) {\n int ans = 0;\n unordered_map<int, int> freqMap;\n\n // Build a freq...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ Solution || Brute Force
c-solution-brute-force-by-vaibhav_arya00-usht
Code\ncpp []\nclass Solution {\npublic:\n // Update the function to use long long for calculations\n int solve(vector<int>& nums1, vector<int>& nums2) {\n
Vaibhav_Arya007
NORMAL
2024-10-03T21:56:06.753612+00:00
2024-10-03T21:56:06.753655+00:00
4
false
# Code\n```cpp []\nclass Solution {\npublic:\n // Update the function to use long long for calculations\n int solve(vector<int>& nums1, vector<int>& nums2) {\n int count = 0;\n\n for (int i = 0; i < nums1.size(); i++) {\n long long target = (long long)nums1[i] * nums1[i]; // Square of num...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Hashing || Super Simple || C++
hashing-super-simple-c-by-lotus18-ppmx
Code\n\nclass Solution \n{\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) \n {\n map<long long,int> m1, m2;\n for(auto n
lotus18
NORMAL
2024-08-18T17:41:20.534244+00:00
2024-08-18T17:41:20.534296+00:00
20
false
# Code\n```\nclass Solution \n{\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) \n {\n map<long long,int> m1, m2;\n for(auto n: nums1) m1[(long long)n*n]++;\n for(auto n: nums2) m2[(long long)n*n]++;\n int ans=0;\n for(int x=0; x<nums2.size(); x++)\n {\...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Simple and Easy JAVA Solution using HashMap
simple-and-easy-java-solution-using-hash-jwoj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Triyaambak
NORMAL
2024-07-29T18:02:41.906735+00:00
2024-07-29T18:02:41.906788+00:00
26
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
✅ C++ Solution in O(mn) complexity clearly explained with comments
c-solution-in-omn-complexity-clearly-exp-1303
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
rohith_nair_2021
NORMAL
2024-07-15T19:12:19.482418+00:00
2024-07-15T19:12:19.482439+00:00
27
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: ```O(mn)```\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: ```O(n) or O(m) depending on which is larg...
0
0
['Array', 'Hash Table', 'C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Clean Python Solution, TC : O(n*m) , SC : O(n+m)
clean-python-solution-tc-onm-sc-onm-by-a-qu8f
Approach\n Describe your approach to solving the problem. \n1. We need to take every squares of nums1 and find product pairs in nums2 and viceversa.\n\n2. So we
AGHIL_P
NORMAL
2024-07-03T17:44:47.259616+00:00
2024-07-03T17:44:47.259659+00:00
48
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We need to take every squares of nums1 and find product pairs in nums2 and viceversa.\n\n2. So we can take the count of squares in both array to minimise repititive work, like if there are same numbers mutiple times. And save the squares and their ...
0
0
['Hash Table', 'Counting', 'Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
O(N2) complexity
on2-complexity-by-sirispandana77-hppb
Intuition\n Describe your first thoughts on how to solve this problem. \nIf the target value is a multiple of the element in the list, then the % will be 0. To
sirispandana77
NORMAL
2024-07-01T18:37:13.303930+00:00
2024-07-01T18:37:13.303956+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf the target value is a multiple of the element in the list, then the % will be 0. To avaoid mulitple calculation a dict can be used to store the values.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo calculate ...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Easy Two Maps Approach
easy-two-maps-approach-by-aman_91-d6ny
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
aman_91
NORMAL
2024-05-20T10:03:19.686405+00:00
2024-05-20T10:03:19.686432+00:00
31
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Solution Number of Ways Where Square of Number Is Equal to Product of Two Numbers
solution-number-of-ways-where-square-of-5c5yu
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Suyono-Sukorame
NORMAL
2024-05-18T09:42:03.244072+00:00
2024-05-18T09:42:03.244101+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['PHP']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Short & Simple. O(n^2 + m^2)
short-simple-on2-m2-by-3s_akb-dzzg
\npublic class Solution {\n\n int c(int[] a, int[] b)\n {\n int res = 0;\n var aa = a.Select(x => (long)x * (long)x).GroupBy(x => x).ToDicti
3S_AKB
NORMAL
2024-05-07T15:29:09.710580+00:00
2024-05-07T15:29:09.710600+00:00
3
false
\npublic class Solution {\n\n int c(int[] a, int[] b)\n {\n int res = 0;\n var aa = a.Select(x => (long)x * (long)x).GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());\n for (int i = 0; i < b.Length; i++)\n for (int k = i + 1; k < b.Length; k++)\n if (aa.Conta...
0
0
['C#']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java Solution with HashMap and binary search
java-solution-with-hashmap-and-binary-se-h2iu
Intuition\nCounting, HashMap and binary search\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\n Add your ti
jhapranay
NORMAL
2024-04-30T19:24:29.044549+00:00
2024-04-30T19:24:29.044579+00:00
20
false
# Intuition\nCounting, HashMap and binary search\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution...
0
0
['Hash Table', 'Binary Search', 'Counting', 'Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python 3: FT 100%, LMT 90%: TC O(N1 log(N1) + N2 log(N2) + S1 + S2): Count and Sort Uniques
python-3-ft-100-lmt-90-tc-on1-logn1-n2-l-oy0z
Intuition\n\nWelcome to my ~6th FT 100% algorithm!\n\nAnd asymptotically it could be even faster on large inputs, see below about iterating over divisors and th
biggestchungus
NORMAL
2024-03-23T21:33:25.248135+00:00
2024-03-23T21:33:25.248151+00:00
30
false
# Intuition\n\nWelcome to my ~6th FT 100% algorithm!\n\nAnd asymptotically it could be even faster on large inputs, see below about iterating over divisors and the excellent average case complexity.\n\nSuper brute force is to do a three-pointer algorithm, checking all triplets and counting up the number of matches. But...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python (Simple Hashmap)
python-simple-hashmap-by-rnotappl-zm56
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
rnotappl
NORMAL
2024-03-15T10:49:44.100186+00:00
2024-03-15T10:49:44.100209+00:00
33
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
C++ || Similar to two sum problem with hash map
c-similar-to-two-sum-problem-with-hash-m-97fq
\n\n# Code\n\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n std::unordered_map<int, int> m1, m2;\n\n
Gismet
NORMAL
2024-03-04T08:41:56.252004+00:00
2024-03-04T08:41:56.252037+00:00
28
false
\n\n# Code\n```\nclass Solution {\npublic:\n int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n std::unordered_map<int, int> m1, m2;\n\n for(int i : nums1)\n m1[i]++;\n \n for(int i : nums2)\n m2[i]++;\n\n int ans = 0;\n for(const auto& [k1, v1...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Easy solution Using two Hashmaps.
easy-solution-using-two-hashmaps-by-abhi-8uex
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Create two hashmaps
abhishek_biyani08
NORMAL
2024-02-26T14:59:40.620685+00:00
2024-02-26T14:59:40.620721+00:00
23
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Create two hashmaps to store the products of each pair of numbers in each array.\n2. Add the products in the hashmaps respectively.\n3. Using for loop check if the ...
0
0
['C++']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
JS || Solution by Bharadwaj
js-solution-by-bharadwaj-by-manu-bharadw-gynl
Code\n\nvar numTriplets = function (nums1, nums2) {\n return Triplets(nums1, nums2) + Triplets(nums2, nums1);\n\n function Triplets(nums1, nums2) {\n
Manu-Bharadwaj-BN
NORMAL
2024-02-01T07:24:15.244179+00:00
2024-02-01T07:24:15.244210+00:00
16
false
# Code\n```\nvar numTriplets = function (nums1, nums2) {\n return Triplets(nums1, nums2) + Triplets(nums2, nums1);\n\n function Triplets(nums1, nums2) {\n let res = 0;\n for (let i = 0; i < nums1.length; i++) {\n let target = nums1[i] * nums1[i], map = new Map();\n for (let j =...
0
0
['JavaScript']
1
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Java simple hashmap solution
java-simple-hashmap-solution-by-dsa_geek-4alj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \ncreated a check functio
dsa_geek
NORMAL
2024-01-01T05:52:58.853158+00:00
2024-01-01T05:52:58.853206+00:00
34
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ncreated a check function which checks the condition given in the question. and this check function is called twice as asked in question.\n\n# Code\n```\nclass Solution...
0
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
java simple HashMap
java-simple-hashmap-by-trivedi_cs1-pvio
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
trivedi_cs1
NORMAL
2023-12-29T09:35:20.014554+00:00
2023-12-29T09:35:20.014576+00:00
9
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers
Python Simple Approach
python-simple-approach-by-raj_zinzuvadiy-64ax
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Raj_Zinzuvadiya
NORMAL
2023-12-27T19:23:28.978132+00:00
2023-12-27T19:23:28.978159+00:00
31
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n^2)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ \n<!-- Add your space complexity ...
0
0
['Python3']
0