You are viewing a single comment's thread. Return to all comments →
I can't figure out what I'm doing partially wrong. I mean I cleared all the cases, but I had to consider r==1 as a special case:
HashMap<Long, Long> counter2 = new HashMap<Long, Long>(); HashMap<Long, Long> counter3 = new HashMap<Long, Long>(); long tot = 0; for (Long elem : arr) { counter2.put(elem * r, counter2.getOrDefault(elem * r, 0l) + 1l); if (counter2.containsKey(elem)) { counter3.put(elem * r, counter3.getOrDefault(elem * r, 0L) + counter2.get(elem)); } tot += counter3.getOrDefault(elem, 0L); } if (r == 1l) { Long tot_r1 = 0l; for (Long count : counter2.values()) { tot_r1 += count * (count - 1) * (count - 2) / 6l; } return tot_r1; } return tot;
How do you avoid the r==1 case?
Seems like cookies are disabled on this browser, please enable them to open this website
Count Triplets
You are viewing a single comment's thread. Return to all comments →
I can't figure out what I'm doing partially wrong. I mean I cleared all the cases, but I had to consider r==1 as a special case:
How do you avoid the r==1 case?