Interview Questions

  • View all interview questions
  • blank
  • Merge two sorted linked lists
    This is a common interview question testing basic knowledge of linked lists. The goal here is merge two linked lists that are already sorted. For example: if L1 = 1 -> 3 -> 10 and L2 = 5 -> 6 -> 9 then your program should output the linked list 1 -> 3 -> 5 -> 6 -> 9 -> 10.

    Algorithm




    You need to be a premium member to see the rest of this question and code.

    mrdaniel published this on 11/24/15 | linked list, sorting, merge, Amazon, Microsoft
    Comments
  • +
  • 1
  • -
  • @crp2002, It does this simply because JavaScript doesn't want to print out every single object that is within an object that is within an object etc... so it stops at the fourth level. If you run the code in your console then you should be able to show the contents of that object!
  • +
  • 1
  • -
  • Hi, sort of new to programming, I understand the solution. However, why does the console only shows until n5, and then object? I would was thinking it would show something like this {data: 1, next: { data: 3, next: { data: 5, next:{data:6, next:{data:9, next:{data:10, next:null}}}} } } Thanks!
    Login to submit a comment