Saturday, December 5, 2009

Finding whether 2 arrays are intersecting

Here are 2 arrays:
A1   1 8 7 5 6
A2   0 9 6 4 2

These two are intersecting at 6.

This can be solved using Hash Tables.
Take 1 Hash Table.
Insert elements from A1 in Hast Table as key and put value in front of them
(In case elemente get repeated increment the value count).
Now traverse the second array A2 and check for element as a key.If you find
it decrement the value and put it in array else continue to next element in

No comments:

Post a Comment