how about this? take pointer p1 set to end of array A and pointer p2 set to end of array B.
while(you get n values) { print A(p1),B(p2) now if( A(p1-1)+B(p2) > A(p1)+B(p2-1) ) then print A(p1-1),B(p2) followed by print A(p1),B(p2-1) decrement p2 and p1 both } m i missing something? On Jul 9, 4:24 am, Piyush Sinha <ecstasy.piy...@gmail.com> wrote: > Given two sorted positive integer arrays A(n) and B(n). We define a > set S = {(a,b) | a in > A and b in B}. Obviously there are n^2 elements in S. The value of such > a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs > from S with largest values. The tricky part is that we need an O(n) > algorithm. > > -- > *Piyush Sinha* > *IIIT, Allahabad* > *+91-8792136657* > *+91-7483122727* > *https://www.facebook.com/profile.php?id=100000655377926* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.