873. Length of Longest Fibonacci Subsequence Medium
1/**
2 * [873] Length of Longest Fibonacci Subsequence
3 *
4 * A sequence x1, x2, ..., xn is Fibonacci-like if:
5 *
6 * n >= 3
7 * xi + xi+1 == xi+2 for all i + 2 <= n
8 *
9 * Given a strictly increasing array arr of positive integers forming a sequence, return the length of the longest Fibonacci-like subsequence of arr. If one does not exist, return 0.
10 * A subsequence is derived from another sequence arr by deleting any number of elements (including none) from arr, without changing the order of the remaining elements. For example, [3, 5, 8] is a subsequence of [3, 4, 5, 6, 7, 8].
11 *
12 * Example 1:
13 *
14 * Input: arr = [1,2,3,4,5,6,7,8]
15 * Output: 5
16 * Explanation: The longest subsequence that is fibonacci-like: [1,2,3,5,8].
17 * Example 2:
18 *
19 * Input: arr = [1,3,7,11,12,14,18]
20 * Output: 3
21 * Explanation: The longest subsequence that is fibonacci-like: [1,11,12], [3,11,14] or [7,11,18].
22 *
23 * Constraints:
24 *
25 * 3 <= arr.length <= 1000
26 * 1 <= arr[i] < arr[i + 1] <= 10^9
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/
32// discuss: https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn len_longest_fib_subseq(arr: Vec<i32>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_873() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.