Wednesday, December 06, 2006

Maxed out...

Tuesday evening... Slightly bored....

Teammate comes to me n rags with following 'problem' which requires an algorithm.....

Given an array A of numbers (sorted, unsorted, negative ....could be anything) , find the most efficient (focus more on time than on memory) algo to calculate MAX ( A[i] - A[j] ) where i 'is less than' j ( couldn't write the 'less than sign' without a hack, cos blogger didn't allow me to do so....you learn something everyday.......)

Do something better than O(n^2) please....
Of course no solutions like sort the array and then do the calculation n stuff....

Where are the comments, with ur solutions??!?! Flowing like mud around here.....

O.S : I think I have written an algorithm for the above problem....Too lazy to check it for multiple cases.....Cmon Kattu!

1 comment:

Karan said...
This comment has been removed by a blog administrator.