arrays - Highest Percentage Increase -
lets have following set of numbers representing values on time
1 2 3 10 1 20 40 60
now looking algorithm find highest percentage increase 1 time another. in above case, answer pair (1, 60), has 6000% increase.
so far, best algorithm can think of brute-force method. consider possible pairs using series of iterations:
1st iteration:
1-2 1-3 1-10 .. 1-60
2nd iteration
2-3 2-10 2-1 ... 2-60
(etc.)
this has complexity o(n3).
i've been thinking approach. find strictly increasing sequences, , determine perecentage increase in strictly increasing sequences.
does other idea strike guys? please correct me if ideas wrong!
i may have misunderstood problem, seems want largest , smallest numbers, since 2 numbers matter.
while true: indexofmax = max(list) indexofmin = min(list) list.remove(indexofmax) list.remove(indexofmin) if(indexofmax < indexofmin) contine else if(indexofmax == indexofmin) return -1 else success
Comments
Post a Comment