You are viewing a single comment's thread. Return to all comments →
Hi please my code fails at test case 6 (not R ==1), any hints would be appreciated.
public static long countTriplets(List<Long> arr, long r) { HashMap<Long, Long> v1 = new HashMap<>(); HashMap<Long, Long> v2 = new HashMap<>(); long count = 0; for (Long digit : arr) { if (v2.containsKey(digit / r)) { count += v2.get(digit / r); } if (v1.containsKey(digit / r)) { long c = v1.get(digit / r); v2.put(digit, v2.getOrDefault(digit, 0L) + c); } v1.put(digit, v1.getOrDefault(digit, 0L) + 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 →
Hi please my code fails at test case 6 (not R ==1), any hints would be appreciated.