Arrays n Hashing Flashcards
1
Q
Find two repeated
A
The trick here is to modify the current array by using element as index in range 0 to n-1 and multiply by -1 to keep track of element. Use arr[abs(arr[i])] *= -1
2
Q
Hashing for pair-2 sum
A
In case of distinct elements, we can just use a set. In case duplicates are present, store count of elements in the map.