Separating merged array of arithmetic and geometric series

Posted by user1814037 on Programmers See other posts from Programmers or by user1814037
Published on 2012-12-07T08:56:44Z Indexed on 2012/12/07 11:19 UTC
Read the original article Hit count: 243

Filed under:
|

Given an array of positive integers in increasing order. Separate them in two series, an arithmetic sequence and geometric sequence. The given array is such that a solution do exist.

The union of numbers of the two sequence must be the given array.
Both series can have common elements i.e. series need not to be disjoint.
The ratio of the geometric series can be fractional.

Example:

Given series : 2,4,6,8,10,12,25
AP: 2,4,6,8,10,12
GP: 4,10,25

I tried taking few examples but could not reach a general way. Even tried some graph implementation by introducing edges if they follow a particular sequence but could not reach solution.

© Programmers or respective owner

Related posts about math

Related posts about sequence