You are viewing a single comment's thread. Return to all comments →
Here is the same thing in Java: -
HashSet<Integer> map = new HashSet<>(); for(int i=0; i<arr.length; i++){ map.add(arr[i]); } int pairCount = 0; for(int i=0; i<arr.length; i++){ if(map.contains(arr[i]-k)){ pairCount++; } } return pairCount;
Time complexity would be O(n). Typically fetching from a HashSet is O(1). Space complexity would also be O(n).
Passed all test cases.
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
Here is the same thing in Java: -
Time complexity would be O(n). Typically fetching from a HashSet is O(1). Space complexity would also be O(n).
Passed all test cases.