-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Adds Longest Arithmetic Subsequence (Review Reqd) #11712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it closed?
for more information, see https://pre-commit.ci
I am working on it currently, no its not closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some more tests?
for more information, see https://pre-commit.ci
hey @tianyizheng02, can you please review this PR! |
Describe your change:
Summary:
This PR adds an implementation of the Longest Arithmetic Subsequence algorithm in Python. The function computes the length of the longest arithmetic subsequence from an input list of integers.
Key Features:
Implements the function longest_arithmetic_subsequence(nums: List[int]) -> int which:
Returns the length of the longest arithmetic subsequence.
Handles edge cases like empty arrays and None input.
Changes:
Added a function to calculate the longest arithmetic subsequence, supporting dynamic programming.
Added type hints using List from the typing module for clarity and static type checking.
The algorithm returns the length of the longest subsequence while ensuring:
For an empty array, the result is 0.
For a None array, a ValueError is raised.
Checklist: