do both s[i-2] and s[i-1] need to be checked? isn't by construction s[i-1]>=s[i-2] ? what about s[i] = max( s[i-2]+a[i], s[i-1], a[i]) ?
On Wed, Jul 20, 2011 at 3:48 AM, Piyush Sinha <ecstasy.piy...@gmail.com>wrote: > ya nitish above condition will do.... > > On 7/20/11, Nitish Garg <nitishgarg1...@gmail.com> wrote: > > I think: > > s[i] = max(s[i-2], s[i-2]+a[i], s[i-1], a[i]) should satisfy all the > cases, > > even when all the numbers are negative. > > Pleas check. > > > > On Wed, Jul 20, 2011 at 12:44 AM, pnandy <sayantan.nand...@gmail.com> > wrote: > > > >> > >> > >> On Jul 19, 8:00 pm, ankit sambyal <ankitsamb...@gmail.com> wrote: > >> > @Nitish and Shubam : Since we trying to find sub sequence and not a > >> > sub string, so if there are negative nos. in the array, just neglect > >> > them. > >> > Piyush's algo will work perfectly...... > >> > >> Piyush's algo won't work for -ve nos. > >> Consider an array -12 -10 5.....answer should be 5 while the algo > >> gives -7 as the answer. > >> > >> -- > >> 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. > >> > >> > > > > -- > > 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. > > > > > > > -- > *Piyush Sinha* > *IIIT, Allahabad* > *+91-7483122727* > * <https://www.facebook.com/profile.php?id=100000655377926> "NEVER SAY > NEVER" > * > > -- > 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. > > -- 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.