K16
Middle of the Linked List
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) -> intInput & 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 indekstirExample 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:
2Example 2: Çift Sayıda
Input:
[[[1,1],[2,2],[3,3],[4,4],[5,5],[6,-1]],0]Expected Output:
3Example 3: Karışık İndeks
Input:
[[[2,1],[3,-1],[1,0]],2]Expected Output:
0