Wednesday, April 13, 2011

Finding pairs

Two integer arrays, write a function to get pairs of number
Ex:
input: [2,5,6,8,10,2,3,5] & [4,7,3,5,2,10,2,4] output:[2,2,3,5,10]
input: [2,2,2,3,4,5,6,7] & [2,2,5,5,7,10] output: [2,2,5,7]


Sol.
1. Sort the smaller array.
2. Use a pointer on the unsorted array to search from beginng to end.

No comments: