Merge Two Sorted Linked Lists in Javascript
Problem : Given list l1 = 1->2->3. And list l2 = 10->20->30. Generate a new list mergedList = 1->2->3->10->20->30. Given list l1 = 1->3->4. And list l2 = 1->2->3. Generate a new list mergedList...
Problem : Given list l1 = 1->2->3. And list l2 = 10->20->30. Generate a new list mergedList = 1->2->3->10->20->30. Given list l1 = 1->3->4. And list l2 = 1->2->3. Generate a new list mergedList...
Problem : Given a linked list, implement an algorithm which returns the node at the beginning of the loop. This post is a follow-up of – JavaScript Linked List Example – Detect a loop...
Input : A linked list Output: An integer This post is a follow-up of – JavaScript Linked List Example – Detect a loop in cycliccircular linked list. I recommend reading those posts first, as...
Logic : If a linked list has a cycle then no node has a null as next pointer. A simple loop exists when p1.next.next !== null as shown below. While iterating over the linked...
Problem description : Convert a given binary tree to a linked list of all the nodes at each depth (if you have a binary tree with depth D, you’ll have D linked lists). Logic...
Problem description : Write a function to determine if a singly linked list is a palindrome. Input : A linked list Output : Boolean (true or false) Approach 1: Reverse and compare the linked...
Problem description : Write a function to reverse a singly linked list. Input : A linked list Output : A linked list Logic : Iterate through linked list with three-pointers previous, current, next. While...
Problem description : Write code to partition a linked list around a value val, such that all nodes less than val come before all nodes greater than or equal to val. Input : A...
Problem description : Implement a non-recursive algorithm to find the kth to last element of a singly linked list. Input : A linked list Output : A value of a node in a linked...
Problem description : Write a method to remove a node from a linked list. Input: A linked list Output: A linked list with one less node Logic : Iterate through the list, if you...