MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / tupleSameProduct

Method tupleSameProduct

TupleWithSameProduct.java:2–21  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int tupleSameProduct(int[] nums) {
3 HashMap<Integer, Integer> productMap = new HashMap<>();
4 int n = nums.length;
5 for(int i=0;i<n;i++){
6 for(int j=i+1;j<n;j++){
7 int res = nums[i] * nums[j];
8 productMap.put(res, productMap.getOrDefault(res,0)+1);
9 }
10 }
11 int ans=0;
12 for(Map.Entry<Integer, Integer> entry : productMap.entrySet()){
13 int product = entry.getKey();
14 int count = entry.getValue();
15 if(count>=2){
16 int comb = (count * (count-1))/2;
17 ans = ans + comb*8;
18 }
19 }
20 return ans;
21 }
22}

Callers

nothing calls this directly

Calls 1

getValueMethod · 0.80

Tested by

no test coverage detected