Class Solution
java.lang.Object
g0801_0900.s0873_length_of_longest_fibonacci_subsequence.Solution
873 - Length of Longest Fibonacci Subsequence.<p>Medium</p>
<p>A sequence <code>x<sub>1</sub>, x<sub>2</sub>, …, x<sub>n</sub></code> is <em>Fibonacci-like</em> if:</p>
<ul>
<li><code>n >= 3</code></li>
<li><code>x<sub>i</sub> + x<sub>i+1</sub> == x<sub>i+2</sub></code> for all <code>i + 2 <= n</code></li>
</ul>
<p>Given a <strong>strictly increasing</strong> array <code>arr</code> of positive integers forming a sequence, return <em>the <strong>length</strong> of the longest Fibonacci-like subsequence of</em> <code>arr</code>. If one does not exist, return <code>0</code>.</p>
<p>A <strong>subsequence</strong> is derived from another sequence <code>arr</code> by deleting any number of elements (including none) from <code>arr</code>, without changing the order of the remaining elements. For example, <code>[3, 5, 8]</code> is a subsequence of <code>[3, 4, 5, 6, 7, 8]</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [1,2,3,4,5,6,7,8]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The longest subsequence that is fibonacci-like: [1,2,3,5,8].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,3,7,11,12,14,18]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= arr.length <= 1000</code></li>
<li><code>1 <= arr[i] < arr[i + 1] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
lenLongestFibSubseq
public int lenLongestFibSubseq(int[] arr)
-