We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi Monks The following algorithm seems to need 4+N+M memory ... and therefore fulfills the challenge :-)
So in additon to N and M, you need the constant space for 4 variables (i, j, val, nextval) and for the temporary sums. :-) Rata (*) 2 * N * M for the inner loop - and a maximum N * M for the outer one note: the restriction that N and M are sorted can easily be dropped with the algorithm above (just replace line 1 with lines 2.2.-2.5) update: Limbic~Region just told me that blokhead posted nearly the same solution before (he needs one variable more, which doesn't affect the complexity O((NM)^2). ... I didn't want to waste bandwidth, but I fear duplicated solutions are the risk if one is not cheating ;-) In reply to Re: Challenge: Sorting Sums Of Sorted Series
by Ratazong
|
|