Tap here to switch tabs
Problem
Ask
Submissions

Problem: Odd Even Linked List

med
30 min
Understand how to rearrange nodes in a singly linked list so that all nodes at odd indexes appear before even-indexed nodes, preserving their original relative order. Learn to solve this problem with in-place manipulation using constant extra space and linear time complexity, enhancing your coding interview pattern skills.

Statement

Given the head of a singly linked list, rearrange the nodes so that all nodes at odd indexes appear first, followed by all nodes at even indexes.

  • The first node in the list is considered at odd index 1, the second at even index 2, and so on.

  • Within the odd group and the even group, the relative order of the nodes must remain the same as in the original list.

Return the head of the reordered linked list.

Note: You must solve the problem in O(1)O(1) extra space complexity and O(n)O(n) time complexity.

Constraints:

  • The number of nodes in the linked list is in the range [0,103][0, 10^3].

  • 103-10^3 \leq Node.val 103\leq 10^3

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Odd Even Linked List

med
30 min
Understand how to rearrange nodes in a singly linked list so that all nodes at odd indexes appear before even-indexed nodes, preserving their original relative order. Learn to solve this problem with in-place manipulation using constant extra space and linear time complexity, enhancing your coding interview pattern skills.

Statement

Given the head of a singly linked list, rearrange the nodes so that all nodes at odd indexes appear first, followed by all nodes at even indexes.

  • The first node in the list is considered at odd index 1, the second at even index 2, and so on.

  • Within the odd group and the even group, the relative order of the nodes must remain the same as in the original list.

Return the head of the reordered linked list.

Note: You must solve the problem in O(1)O(1) extra space complexity and O(n)O(n) time complexity.

Constraints:

  • The number of nodes in the linked list is in the range [0,103][0, 10^3].

  • 103-10^3 \leq Node.val 103\leq 10^3