@surender
yup , thanx for pointing :)
On Tue, Jul 26, 2011 at 7:27 AM, surender sanke <[email protected]> wrote:
> @anurag , it fails for {4,5,-2,0,-3,-4,4,2,3,5,-7};
> urs calculates from index 4 to 9.
> but maximum product is from index 5 to 10
>
> surender
>
> On Mon, Jul 25, 2011 at 11:38 AM, Anurag atri <[email protected]>wrote:
>
>> Time O(n) , Space O(1)
>>
>>
>> int maximum_continuous_product ( int numbers[] , int size )
>> {
>> int i ;
>> int before_negative = 0 ;
>> int current_p = 1 ;
>> int max_p = 0 ;
>> int is_negative = 0 ;
>>
>>
>> for ( i = 0 ; i < size ; i ++ )
>> {
>> if ( numbers[i] < 0 )
>> {
>> if ( is_negative == 0 )
>> {
>> is_negative = 1 ;
>> }
>> else
>> {
>> is_negative = 0 ;
>> }
>> if ( before_negative == 0 )
>> {
>> before_negative = current_p ;
>> current_p *= -1 ;
>> }
>> else
>> {
>> current_p *= -1 ;
>> current_p *= before_negative ;
>> before_negative = 0 ;
>> }
>> }
>>
>> current_p *= numbers[i] ;
>> if ( is_negative == 0 )
>> {
>> if ( current_p > max_p )
>> {
>> max_p = current_p ;
>> }
>> }
>>
>> if ( current_p == 0 )
>> {
>> current_p = 1 ;
>> before_negative = 0 ;
>> is_negative = 0 ;
>> }
>> }
>> return max_p ;
>>
>> }
>>
>> --
>> 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.
>
--
Regards
Anurag Atri
III year
Computer Engineering
Delhi College Of Engineering
--
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.