Split Linked List in alternating way

Problem Given a singly linked list, split it into two linked lists. These linked lists will contain the alternate nodes from the given linked list. Examples Example 1: head = [1,2,3,4,5] Output: [ [1, 3, 5], [2, 4] ] ...

K reverse a Linked List in alternating way

Problem Given a singly linked list and a number k, write an algorithm to reverse every alternate k nodes in the linked list. If there are fewer than k nodes left at the end, leave them as is. Examples Example 1: --- title: Input --- graph LR A1[1] --> B2[2] --> C3[3] --> D4[4] --> E5[5] --> F6[6] --> G7[7] --> H8[8] classDef swapped fill:#ffcc00,stroke:#000,stroke-width:2px; ...

Swap alternate nodes in a singly linked list

Problem Given a single Linked List. Swap every other alternate nodes. Examples Example 1: Input: head = 1 -> 2 -> 3 -> 4 -> 5 -> null Output: 3 -> 4 -> 5 -> 1 -> 2 -> null Explanation: The list was transformed in several steps. 1. First step, swap 1 and 3 i.e. 3–>2–>1–>4–>5–>null 2. Second step, swap 2 and 4 i.e. 3–>4–>1–>2–>5–>null 3. last step, swap 1 and 5, i.e. 3–>4–>5–>2–>1–>null ...

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. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy