K16

Middle of the Linked List

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: NUMERIC

Problem Statement & Objective

Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.

Function Signature (Python)

middle_node(nodes: list[list[int]], head: int) -> int

Input & Output Contract

Output Rule:Orta düğümün 0-tabanlı indeksi. Çift uzunlukta ikinci orta.

System Constraints

1 <= dugumler.length <= 100
Döngü yoktur
bas geçerli bir indekstir

Example Execution Walkthrough

[[1,1],[2,2],[3,3],[4,4],[5,-1]], bas = 0
Zincir 0→1→2→3→4, orta indeks 2 (değer 3).

[[2,1],[3,-1],[1,0]], bas = 2
Zincir indeks 2 → 0 → 1 (değerler 1, 2, 3). Orta indeks 0.
len(dugumler)//2 = 1 bu cevap değildir.

Example Test Scenarios (3)

Example 1: Tek Sayıda
Input:[[[1,1],[2,2],[3,3],[4,4],[5,-1]],0]
Expected Output:2
Example 2: Çift Sayıda
Input:[[[1,1],[2,2],[3,3],[4,4],[5,5],[6,-1]],0]
Expected Output:3
Example 3: Karışık İndeks
Input:[[[2,1],[3,-1],[1,0]],2]
Expected Output:0
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      3,
      3
    ],
    [
      4,
      4
    ],
    [
      5,
      -1
    ]
  ],
  0
]
Expected Output
2