i was going through a problem WAP to find all pairs of integers whose sum is equal to a given number
i check solution using hashing they say time complexity is O(n) but when i checked hashmap implementation, below program uses two iteration, one is using for another iteration is within contains method of
hashmap
so time complexity should be O(n^2) not O(n)
Please correct if i am wrong
`static int getPairsCount(int arr[], int n, int k)
{
HashMap<Integer,Integer> m = new HashMap<>();
int count = 0;
for (int i = 0; i < n; i++) {
if (m.containsKey(k - arr[i])) {
count += m.get(k - arr[i]);
}
if(m.containsKey(arr[i])){
m.put(arr[i], m.get(arr[i])+1);
}
else{
m.put(arr[i], 1);
}
}
return count;
}`