You are viewing a single comment's thread. Return to all comments →
Java:
public static int pairs(int k, List<Integer> arr) { int pairsCount =0; Set<Integer> arrSet = arr.stream().collect(Collectors.toSet()); for (Integer item : arr) { if (arrSet.contains(item+k)) { pairsCount++; } } return pairsCount; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Pairs
You are viewing a single comment's thread. Return to all comments →
Java: