I think O(n) is the best time complexity. Try to think about one sequence
with all negative numbers or positive numbers. we can't get the full
information without one time iteration, or we can just say the data reading
time will cost O(n).

2011/4/21 hary rathor <harry.rat...@gmail.com>

> Problem; print the largest subset of negative number in array of integers
>
> i have code it in following way which is give solution in O(n) and and
> required memory in O(n)
>  any tell me other method better then this O(n) .
> pls tell me is it any bug in the code
>
>
> #include<stdio.h>
>
> int count=0,ind=-1,len,i=0;
> void largestNegSubset(int arr[])
> {
> if(i>len)
> return ;
> int t=0;
> while(arr[i++]<0&&i<=len)t++;
> if(t>count){count=t;ind=i-1;}
> largestNegSubset(arr);
> }
> int main()
> {
>     int arr[]={1,0,1,-6,-7,-2,-2,4,-3,-5,-6,7,-8,-9};
>     len=(sizeof(arr)/sizeof(int));
>     largestNegSubset(arr);
>     for(i=ind-1;i>(ind-count-1);i--)
>     printf("%d,",arr[i]);
>     return 0;
> }
>
>
> --
> 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.

Reply via email to