You can do this in linear time.
First, notice that a geometric progression is just an arithmetic progression in the elementwise logarithm of the sequence. So we can think of having a sequence of pairs of numbers that we want to cover with a progression that is arithmetic in the first element and a progression that is arithmetic in the second element.
Two of the first three elements must lie in the same progression. Without loss of generality, I'll assume it's the arithmetic progression. You can find, in linear time, the longest arithmetic sequence with the right beginning and common difference that is a subsequence of your input. You do that and then you're left with a bunch of uncovered elements; say their logarithms are g_1, g_2, ..., g_k.
Find the "greatest common divisor" of g_2-g_1, ..., g_k-g_1 --- I want the biggest real number d such that g_2-g_1, g_3-g_1, ..., g_k-g_1 can all be written as multiples of d.
Then, if there is a geometric progression covering g_1, ..., g_k that is a subsequence of your input, there must be one with common ratio d. All you need to do is check that g_1, g_1 * exp(d), g_1 * exp(2d), ..., g_k are all elements of your input, and you can do this in linear time.
So you do the above six times (twice --- arithmetic and geometric --- for each of the three possible choices of "first two"), and the above takes linear time.
2,4,6,8,10,12,25
, I would say that2,4,6,10,12
and25
is also a solution. If25
isn't valid, pick any arbitrary number from the first set and add it to the second and voila!, another solution. – David Hammen Dec 7 '12 at 15:22