Agreed finding the largest is O(n). Finding the largest k will be O(n log
k). Just coz we don't have loops it doesn't mean the op is O(1).
Product of largest 3 does not guarantee largest product! (Take for e.g. -10,
5, 0, -20, 8. The max product is 1600, not 0.
On Wed, Sep 16, 2009 at 2:48 AM, Pra
ya!! i thnk its compiler dependent cz when i tried this in devc++
compiler nd its o/p is 49 not 56...nd i didnt find any explanation to
this...
On Sep 15, 6:40 pm, ankur aggarwal wrote:
> compiler dependent as simple as that..
--~--~-~--~~~---~--~~
You received t
hi all,
i think we can use kth smallest algorithm (from cormen book) to find three
largest numbers from given and multiplication of these number will leads to
max product.
time complexity will be 3*O(n)
3->for finding three largest numbers
O(n)->time complexity of Kth Smallest algorithm
On We
This one is better than what I suggested before. Doable in O(n)!
On Sep 13, 10:10 pm, Dave wrote:
> The following assumest that n >= 5. Find the 3 largest positive
> numbers and the two largest-in-magnitude negative numbers (i.e., the
> two smallest signed numbers).
>
> If there are not two neg
1. Sort the array (say arr) (O(nlgn)
2. Find the position of 0 in the array. The left of the array would be all -ve
and right of the array is all positive. Say zi is the position of zero, so
indices [0, zi) are all -ve and (zi, n-1] are all +ve. (O(lgn). If 0 is not
there in the array, we can st