So you Might to Interested to Review It 

Algorithm

Lets us take an array = { 2,-25,4,5,-3,-5}

We take 3 variables P , N , Val

P=1 , N=0 , Val=0

first value is 2 , A[0] which is +ve . So we multiply both P & N with A[0] .
P=2 , N=0

now V[1] = -25 -ve .

We multiply P with -V[1] & N with -V[1] .

P=50
N=0

As V[1] is -ve we swap P & N .
P=0 , N=50

if V[i] == 0
We initialise P=1 , N=0

if( P < 1 ) /* analogous to kadane's algo's 
if( sumSoFar < 0 ) */ { P=1; N=0; } \
at every step val = max( val , P ) 
We proceed in the same fashion till the end . 


Detail & Working Code 

http://shashank7s.blogspot.com/2011/08/given-array-of-integers-ive-ive-0-find.html

Do Notify me if it will fail for any testcases 

Best Regards
Shashank Mani
Computer Science
Birla Institute of Technology Mesra 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/3SO1V_0XkhoJ.
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.

Reply via email to