Since A(n) and B(n) are sorted so in the pair (a[i], b[j]) either i = n-1 or
j = n-1 or both.
1.) so the first element is (a[n-1], b[n-1])
2.) now, we have two numbers to compare p = a[n-1]+ b[n-2] and q =
a[n-2]+b[n-1]
3.) if p>q then p = a[n-1]+b[n-3]
else q = a[n-3] + b[n-1]
and repeat in the similar fashion
The point to note is, either a's index is n-1 or b's index is n-1.
On Sat, Sep 3, 2011 at 10:18 AM, Siddhartha Banerjee <
[email protected]> wrote:
> yeah piyush's solution seems correct to me... if current amx is from
> a[i],b[j], then next maximum can only be either of a[i-1],b[j] or
> a[i],b[j-1].... continue!!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.