Skip to content
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

Sum of two lists issue #3

Closed
apfel-das opened this issue Feb 17, 2022 · 2 comments
Closed

Sum of two lists issue #3

apfel-das opened this issue Feb 17, 2022 · 2 comments

Comments

@apfel-das
Copy link

def sumOfLinkedLists(linkedListOne, linkedListTwo):

Attempting to test with below list pairs:

[9, 9, 9, 8, 9]
[1, 1, 1, 1, 1]
will most probably generate a resultant list of [0, 1, 1, 0, 1, 1] --> 011011 which violates the idea of summation.

You could try to reverse the list with O(n) instead and then sum the values with the traditional way (head --> tail but due to reverse this would be actually old tail --> old head).

@das-jishu
Copy link
Owner

Hello, apologies for the confusion but the question indicated that for this scenario, the head of the linked list (both the inputs and output) would point to the least significant digit and so on. 1 -> 4 is actually 41.

Going by your example, 9 -> 9 -> 9 -> 8 -> 9 is actually the number 98999.
Similarly, 1 -> 1-> 1-> 1-> 1 is 11111.
Output is: 0 -> 1 -> 1 -> 0 -> 1 -> 1 which is actually 110110.

This satisfies the desired output where they REQUIRE the least significant digit to appear first. In a case where you want to output the digits as they appear (starting with the most significant digit), reversing the list would make sense. Thanks for pointing it out. I will add a comment at the top so people don't get confused.

@apfel-das
Copy link
Author

Sorry about it, you are totally right under this assumption (reverse lists as input/output). Mea culpa ✋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants