O32

Odd Even Linked List

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.

Function Signature (Python)

odd_even_linked_list(nodes: list, head: int) -> list

Input & Output Contract

Output Rule:[yeni_bas, sonraki_listesi]. Boş liste [-1, []].

System Constraints

0 <= dugumler.length <= 10^4
-10^6 <= değer <= 10^6
Döngü yoktur

Example Execution Walkthrough

[[1,1],[2,2],[3,3],[4,4],[5,-1]], bas = 0
Konumlar 1,2,3,4,5. Tekler 0,2,4 sonra çiftler 1,3.
yeni_bas = 0, sonraki = [2, 3, 4, -1, 1]  (0→2→4→1→3)

[[2,3],[4,4],[1,0],[3,1],[5,-1]], bas = 2
Zincir indeksleri 2 → 0 → 3 → 1 → 4 (değerler 1, 2, 3, 4, 5).
Ham dizinin 0::2 dilimi bu gruplamayı vermez.

Example Test Scenarios (3)

Example 1
Input:[[[1,1],[2,2],[3,3],[4,4],[5,-1]],0]
Expected Output:[0,[2,3,4,-1,1]]
Example 2: Tek Düğüm
Input:[[[1,-1]],0]
Expected Output:[0,[-1]]
Example 3: Karışık Depolama
Input:[[[2,3],[4,4],[1,0],[3,1],[5,-1]],2]
Expected Output:[2,[1,-1,3,4,0]]
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      3,
      3
    ],
    [
      4,
      4
    ],
    [
      5,
      -1
    ]
  ],
  0
]
Expected Output
[
  0,
  [
    2,
    3,
    4,
    -1,
    1
  ]
]