You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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).
The text was updated successfully, but these errors were encountered:
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.
algoexpert-data-structures-algorithms/Medium/sum-of-linked-lists.py
Line 11 in e47ba65
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 actuallyold tail --> old head
).The text was updated successfully, but these errors were encountered: