Skip to content

Conversation

@pickled-bot
Copy link

Creating pull request even though test for linkedLists of different size is not passing wanted to open the pull request before getting this test to pass.
Added a test to check if the last node is the same, and to return that node.

current_a = headA
current_b = headB

while headA and headB:
Copy link
Contributor

@char-adadev char-adadev Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super close to getting all the tests to pass, great job!!

For getting that last test to pass, I would take a look at a couple of things:

  • Try running without the outer loop while headA and headB. Is there any difference? You might not need this loop since you're not advancing the pointers for headA and headB.
  • Due to your if, elif, else statement at the bottom of the while headA and headB loop, the loop may just be running one time before returning
  • I would recommend walking through your solution with two small example lists like:

1 -> 2 -> 3
2 -> 3

Do you run into any null pointers while walking through your code?

You may notice that your solution is erroring out on line 32 or line 33 for differing length lists. It seems as if the pointers are advancing one-by-one without making a double check to see if one list has reached the end and resetting the pointer (which you do have a check for in lines 25 through 33!).

I was able to re-work your solution very slightly to get all the tests to pass from my side:

first = None
current_a = headA
current_b = headB

while current_a != current_b:
    if current_a is None and current_b is not None:
        current_a = headA
        current_b = current_b.next
    elif current_b is None and current_a is not None:
        current_b = headB
        current_a = current_a.next
    else:
        current_a = current_a.next
        current_b = current_b.next

if current_a == current_b:
    first = current_a
    return first

elif current_a != current_b:
    return first
else:
    return first

Overall, you did a great job and I can tell you put a lot of effort into this!

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 this pull request may close these issues.

2 participants