| | |
To find the maximum subset sum in an array.
![]() |
Then you mean the maximum sublist sum, not subset.
First, you can convert the list into a list of cumulative sums, turning [5,-2,10,-4] into [0,5,3,13,9]. Then walk through the list of cumulative sums, saving the smallest value so far and the maximum difference between what you see as the current value and what is currently the smallest value.
Of course, you don't have to actually create a list of cumulative sums; you can keep track of the cumulative sum as you walk through the first list.
First, you can convert the list into a list of cumulative sums, turning [5,-2,10,-4] into [0,5,3,13,9]. Then walk through the list of cumulative sums, saving the smallest value so far and the maximum difference between what you see as the current value and what is currently the smallest value.
Of course, you don't have to actually create a list of cumulative sums; you can keep track of the cumulative sum as you walk through the first list.
All my posts may be redistributed under the GNU Free Documentation License.
•
•
•
•
Originally Posted by dilip.mathews
Rashakil,
Seems like a good logic let me try to implement this.
But dont u think that then also I have to walk thru the array twice?
All my posts may be redistributed under the GNU Free Documentation License.
![]() |
Other Threads in the C Forum
- Previous Thread: C Progamming
- Next Thread: Function Problems
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






