As reported: Synopsys R&D Engineer Sr, round 1 (2024): find the middle of a linked list.
Given the head of a singly linked list, return its middle node. If there are two middle nodes, return the second one.
This is LeetCode 876 — Middle of the Linked List.
Example 1
head = [1,2,3,4,5] -> [3,4,5] the node with value 3
Example 2
head = [1,2,3,4,5,6] -> [4,5,6] two middles (3 and 4): return 4
Constraints: 1 ≤ number of nodes ≤ 100; 1 ≤ Node.val ≤ 100.
Code runner format: one line: the list values as a JSON array. Implement middleNode(head); the harness prints the list starting at the returned node.