Dhyanesh wrote: > I agree it is faster but you cannot use it will all inputs. I gave you a > test case and you still havent come out on how to solve that. Your algorithm > is limited to a range of numbers only. It will be very slow even for numbers > like 2^31 or so which fit into the size of an integer (and you can run it > only if you have 2GB virtual memory). Give it such inputs and you will it > will perform much much worse than doing the nlgn algorithm. One more thing > how are you going to handle -ve numbers. > > Tell me how fast it is with this set ... { - 2^30, -23, 64,1 ,4,1 , 2^31 } > ... try make it run faster than nlogn sorting.
What if he use a hash table instead of an array? The hash table only need to be a little bit bigger than to original array and could use very big (or even negative) index. Mathieu Pagé