Discover long patterns

前端 未结 6 1817
逝去的感伤
逝去的感伤 2021-01-30 02:20

Given a sorted list of numbers, I would like to find the longest subsequence where the differences between successive elements are geometrically increasing. So if the list is <

6条回答
  •  悲哀的现实
    2021-01-30 03:18

    In fact it is exactly the same question as Longest equally-spaced subsequence, you just have to consider the logarithm of your data. If the sequence is a, ak, ak^2, ak^3, the logarithmique value is ln(a), ln(a) + ln(k), ln(a)+2ln(k), ln(a)+3ln(k), so it is equally spaced. The opposite is of course true. There is a lot of different code in the question above.

    I don't think the special case a=1 can be resolved more efficiently than an adaptation from an algorithm above.

提交回复
热议问题