Uh oh!
There was an error while loading. Please reload this page.
[NEW ALGORITHM] Rotate linked list by K. - #9278
Conversation
There was a problem hiding this comment.
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 reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto 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.
| return head | ||
| def right_rotate_by_k(head: Node, k: int) -> Node: |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: k
cclauss
commented
Oct 1, 2023
As stated above Also... |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Christian Clauss <cclauss@me.com>
for more information, see https://pre-commit.ci
Co-authored-by: Christian Clauss <cclauss@me.com>
Uh oh!
There was an error while loading. Please reload this page.
cclauss
commented
Oct 1, 2023
Muhammadummerr
commented
Oct 1, 2023
I used the variable "rotation" instead of "k". |
| def right_rotate_by_k(head: Node | None, rotation: int) -> Node | None: | ||
| """ | ||
| Rotate a linked list to the right by rotation times. | ||
| Parameters: | ||
| head (Node | None): The head of the linked list. | ||
| rotation (int): The number of places to rotate. | ||
| Returns: | ||
| Node | None: The head of the rotated linked list\ | ||
| if the linked list is not None, otherwise None. |
There was a problem hiding this comment.
Mypy can test data types in the function signature, but not in the comments.
Do not repeat the datatypes in both places because readers will be confused if one is changed and the other is not.
How about this naming...
| defright_rotate_by_k(head: Node|None, rotation: int) ->Node|None: | |
| """ | |
| Rotatealinkedlisttotherightbyrotationtimes. | |
| Parameters: | |
| head (Node|None): Theheadofthelinkedlist. | |
| rotation (int): Thenumberofplacestorotate. | |
| Returns: | |
| Node|None: Theheadoftherotatedlinkedlist\ | |
| ifthelinkedlistisnotNone, otherwiseNone. | |
| defrotate_to_the_right(head: Node|None, places: int) ->Node|None: | |
| """ | |
| Rotatealinkedlisttotherightbyanumberofplaces. | |
| Parameters: | |
| head: Theheadofthelinkedlist. | |
| places: Thenumberofplacestorotatethelinkedlist | |
| Returns: | |
| TheheadoftherotatedlinkedlistorNoneifthereisnolist. |
There was a problem hiding this comment.
I might even raise a ValueError if I was handed a head=None.
There was a problem hiding this comment.
Do we have a test for a linked list that has just 3 elements but we are asked to shift to the right 10 places?
There was a problem hiding this comment.
What happens if we are asked to shift to the right -2 places? -2.5 places?
There was a problem hiding this comment.
What happens if we are asked to shift to the right -2 places? -2.5 places?
If the rotation number is not an integer, it should raise an error. If it is a negative integer, converting it to a positive integer would be a better idea, right?
There was a problem hiding this comment.
Do we have a test for a linked list that has just 3 elements but we are asked to shift to the right 10 places?
Yes, I tested it, and it is working correctly.
There was a problem hiding this comment.
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 reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto 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.
Uh oh!
There was an error while loading. Please reload this page.
Describe your change:
I have added a new algorithm to rotate a linked list by k times. I have also:
Added the function docstring to provide clear documentation.
Added type hints for function parameters and return values.
Included comments to enhance code readability.
Checklist: