The "Length of Longest Fibonacci Subsequence interview question" asks you to find the length of the longest subsequence in a strictly increasing array that follows the Fibonacci rule (A_i + A_j = A_k). A subsequence is derived by deleting zero or more elements from the original array. This "Length of Longest Fibonacci Subsequence coding problem" is a step up from basic sequence problems, requiring you to identify patterns within a sorted set.
This problem is commonly asked at top-tier companies like Amazon and Goldman Sachs. It tests a candidate's proficiency with the "Dynamic Programming interview pattern" and the "Hash Table interview pattern". It requires an understanding of how to define a state that captures enough information to build upon previous results—in this case, using the last two elements of a potential sequence.
The solution typically involves Dynamic Programming. Since a Fibonacci sequence is determined by its last two terms, we can use a DP table dp[i][j] to store the length of the longest Fibonacci-like subsequence ending with the elements at index i and j. We use a hash map to quickly find the index of the element arr[j] - arr[i] (the required preceding term). If it exists at index k, then dp[i][j] = dp[k][i] + 1.
Array: [1, 2, 3, 4, 5, 6, 7, 8]
When a sequence depends on multiple previous terms, your DP state usually needs to reflect that. Practice 2D DP problems and learn how to map array values to their indices using a Hash Table for O(1) lookups.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Longest Arithmetic Subsequence of Given Difference | Medium | Solve | |
| Delete and Earn | Medium | Solve | |
| Find the Maximum Length of a Good Subsequence I | Medium | Solve | |
| Sum of Good Subsequences | Hard | Solve | |
| Find the Maximum Length of a Good Subsequence II | Hard | Solve |