Skip to content

Commit 487de03

Browse files
committed
Feb 27
1 parent e3816c1 commit 487de03

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def lenLongestFibSubseq(self, arr: list[int]) -> int:
3+
nums = set(arr)
4+
max_len = 0
5+
for i in range(len(arr)):
6+
for j in range(i+1, len(arr)):
7+
n1, n2 = arr[i], arr[j]
8+
length = 0
9+
while n1 + n2 in nums:
10+
n1, n2 = n2, n1 + n2
11+
length += 1
12+
max_len = max(max_len, length)
13+
return max_len + 2 if max_len > 0 else max_len
14+
15+
16+
def main():
17+
arr = [1, 2, 3, 4, 5, 6, 7, 8]
18+
assert Solution().lenLongestFibSubseq(arr) == 5
19+
20+
arr = [1, 3, 7, 11, 12, 14, 18]
21+
assert Solution().lenLongestFibSubseq(arr) == 3
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
| February 24 | [2467. Most Profitable Path in a Tree](https://leetcode.com/problems/most-profitable-path-in-a-tree/) | Medium | Unsolved |
3131
| February 25 | [1524. Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/) | Medium | Solved |
3232
| February 26 | [1749. Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | Unsolved |
33-
| February 27 | []() | | |
33+
| February 27 | [873. Length of Longest Fibonacci Subsequence](https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | Solved |
3434
| February 28 | []() | | |
3535

3636

3737
## Summary
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 18 | 13 | 5 |
41+
| Medium | 19 | 14 | 5 |
4242
| Hard | 1 | 1 | 0 |

0 commit comments

Comments
 (0)