Merge a Linked list into another at Alternate Positions

Problem Given two linked lists, merge one list into another at alternate positions, if second link list has extra nodes, print them as well Examples Example 1: Input: list1 = [1, 2, 3], list2 = [4, 5, 6, 7, 8] Output: [1, 4, 2, 5, 3, 6] Remaining nodes from list2: [7, 8] Explanation: Merged list is formed by taking one element from each list alternately. The remaining elements of list2 are printed. ...

Reverse Linked List 2 - between m and n

Problem Reverse a linked list from position m to n. Do it in-place and in one-pass. OR Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. Examples Example 1: --- title: Input --- graph LR A1[1] --> B2[2]:::reversed --> C3[3]:::reversed --> D4[4]:::reversed --> E5[5] classDef reversed fill:#ffcc00,stroke:#000,stroke-width:2px; ...

Get sqrt nth node in Linked List

Problem Given a singly linked list, write a function to find the $\sqrt[]{n}$ element, where n is the number of elements in the list. Assume the value of n is not known in advance. Follow up Can you do it in one iteration? Examples Input: 1->2->3->4->5->NULL Output: 2 ...

June 19, 2022 · 3 min · TagsList of tags for the post  linkedlist

Delete non-tail Node in linked list, Given only access to that Node

Problem Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list. Examples Example 1: graph LR; 4 --> 5 --> 1 --> 9 style 5 fill:#FF9933 ...

Linked List Cycle 4 - Delete cycle

Problem Given head, the head of a linked list, determine if the linked list has a cycle in it. Return true if there is a cycle in the linked list. Otherwise, return false. Examples Example 1 Input: head = [0, 1, 3, 2, 4] output: [0, 1, 3, 2, 4] Explanation: Cycle starts at node 2 ...

Remove duplicates from an unsorted linked list keeping only one instance

Problem Write code to remove duplicates from an unsorted linked list. FOLLOW UP: How would you solve this problem if a temporary buffer is not allowed? Examples Example 1: 2 -> 3 -> 2 -> 5 -> 2 -> 8 -> 2 -> 3 -> 8 -> null => 2 -> 3 -> 5 -> 8 -> null ...

Find Common Elements in Two Sorted Linked Lists

Problem Given two sorted linked lists, write an algorithm to print the common elements of these lists. The solution should be based on the logic of merge sort. Since the elements in the lists are sorted, we can use a two-pointer technique to efficiently find and print the common elements. Examples: Example 1: Input: list1 = [1, 2, 4, 6, 8], list2 = [2, 4, 6, 8, 10] Output: [2, 4, 6, 8] ...

March 26, 2022 · 2 min · TagsList of tags for the post  linkedlist
This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy