-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Longest Consecutive Sequence LeetCode problem #9686
base: master
Are you sure you want to change the base?
Conversation
removed the class from the solution Co-authored-by: Chris O <[email protected]>
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
||
|
||
def longestConsecutiveSequence(self, nums: List[int]) -> int: | ||
# Create a map of all numbers in the array to their index |
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.
An error occurred while parsing the file: data_structures/arrays/longest_consecutive_sequence.py
Traceback (most recent call last):
File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
reports = lint_file(
^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 10:5.
parser error: error at 9:4: expected one of (, *, +, -, ..., AWAIT, EOF, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~
# Create a map of all numbers in the array to their index
^
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
||
|
||
def longestConsecutiveSequence(self, nums: List[int]) -> int: | ||
# Create a map of all numbers in the array to their index |
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.
An error occurred while parsing the file: data_structures/arrays/longest_consecutive_sequence.py
Traceback (most recent call last):
File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
reports = lint_file(
^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 10:5.
parser error: error at 9:4: expected one of (, *, +, -, ..., AWAIT, EOF, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~
# Create a map of all numbers in the array to their index
^
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
||
""" | ||
|
||
def longestConsecutiveSequence(self, nums: List[int]) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/longest_consecutive_sequence.py
, please provide doctest for the function longestConsecutiveSequence
Variable and function names should follow the snake_case
naming convention. Please update the following name accordingly: longestConsecutiveSequence
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
""" | ||
|
||
|
||
def longest_consecutive_sequence(self, nums: List[int]) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/longest_consecutive_sequence.py
, please provide doctest for the function longest_consecutive_sequence
""" | ||
|
||
|
||
def longest_consecutive_sequence(self, nums: List[int]) -> int: |
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.
Please add doctests here; https://docs.python.org/3/library/doctest.html
""" | ||
|
||
|
||
def longest_consecutive_sequence(self, nums: List[int]) -> int: |
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.
def longest_consecutive_sequence(self, nums: List[int]) -> int: | |
def longest_consecutive_sequence(nums: list[int]) -> int: |
Longest Consecutive Sequence Problem from LeetCode | ||
|
||
""" | ||
|
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.
from collections import defaultdict | |
|
||
2. Then, we loop through the numbers, and for each number n, we check if it's already in seen list. | ||
If so, we skip it. Otherwise, we start counting the length of the consecutive sequence starting from n. | ||
This is done by checking if n+1 is in the dictionary. If so, we increment the counter, and set the seen status of n to 1. |
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.
Please make sure all lines are less than 88 characters long
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
||
""" | ||
//can u add | ||
def longest_consecutive_sequence(nums): |
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.
An error occurred while parsing the file: data_structures/arrays/longest_consecutive_sequence.py
Traceback (most recent call last):
File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
reports = lint_file(
^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 8:3.
parser error: error at 7:2: expected one of (, *, +, -, ..., AWAIT, EOF, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~
def longest_consecutive_sequence(nums):
^
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
date: 4 OCT 2023 | ||
Longest Consecutive Sequence Problem from LeetCode | ||
""" | ||
def longest_consecutive_sequence(nums): |
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.
Please provide return type hint for the function: longest_consecutive_sequence
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: nums
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
""" | ||
|
||
|
||
def longest_consecutive_sequence(nums) -> int: |
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.
Please provide type hint for the parameter: nums
for more information, see https://pre-commit.ci
""" | ||
Finds the length of the longest consecutive sequence in a list of numbers. | ||
|
||
Args: | ||
nums (List[int]): A list of integers. | ||
|
||
Returns: | ||
int: The length of the longest consecutive sequence. | ||
|
||
Examples: | ||
>>> longest_consecutive_sequence([100, 4, 200, 1, 3, 2]) | ||
4 | ||
>>> longest_consecutive_sequence([1, 2, 3, 4, 5]) | ||
5 | ||
>>> longest_consecutive_sequence([5, 4, 3, 2, 1]) | ||
5 | ||
>>> longest_consecutive_sequence([]) | ||
0 | ||
""" |
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.
""" | |
Finds the length of the longest consecutive sequence in a list of numbers. | |
Args: | |
nums (List[int]): A list of integers. | |
Returns: | |
int: The length of the longest consecutive sequence. | |
Examples: | |
>>> longest_consecutive_sequence([100, 4, 200, 1, 3, 2]) | |
4 | |
>>> longest_consecutive_sequence([1, 2, 3, 4, 5]) | |
5 | |
>>> longest_consecutive_sequence([5, 4, 3, 2, 1]) | |
5 | |
>>> longest_consecutive_sequence([]) | |
0 | |
""" | |
""" | |
Finds the length of the longest consecutive sequence in a list of numbers. | |
nums: A list of integers. | |
int: The length of the longest consecutive sequence. | |
>>> longest_consecutive_sequence([100, 4, 200, 1, 3, 2]) | |
4 | |
>>> longest_consecutive_sequence([1, 2, 3, 4, 5]) | |
5 | |
>>> longest_consecutive_sequence([5, 4, 3, 2, 1]) | |
5 | |
>>> longest_consecutive_sequence([]) | |
0 | |
""" |
Please read CONTRIBUTING.md to see how to indent docstrings.
Finds the length of the longest consecutive sequence in a list of numbers. | ||
|
||
Args: | ||
nums (List[int]): A list of integers. |
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.
Please refrain from declaring types within a docstring.
for more information, see https://pre-commit.ci
@ChrisO345 please review this |
add a well documented solution with approach for the leet code problem Longest consecutive Sequence Leet code