You are viewing a single comment's thread. Return to all comments →
Java8 solution
static long countTriplets(List<Long> arr, long r){ Map<Long,Long> v2 = new HashMap<>(); Map<Long,Long> v3 = new HashMap<>(); Long count = 0L; for (Long k:arr) { count+=v3.get(k)==null?0:v3.get(k); if (v2.get(k)!=null) v3.compute(k*r,(key,value)->value!=null?value+v2.get(k):v2.get(k)); v2.compute(k*r,(key,value)->value==null?1:value+1); } return count; }
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 →
Java8 solution