Back to Practice Dashboard
DSA SectionEasy
Middle of Linked List
Learn how to solve the 'Middle of Linked List' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function middle_node(arr) that represents a singly linked list as a Python list arr and returns the sublist starting from the middle node. If there are two middle nodes (even length), return the sublist starting from the second middle node.
Constraints
- •1 <= len(arr) <= 1000
- •-1000 <= arr[i] <= 1000
Examples
Example 1
Input
arr = [1, 2, 3, 4, 5]
Output
[3, 4, 5]
Explanation
The middle node is 3, so we return the list from 3 onwards.
Example 2
Input
arr = [1, 2, 3, 4, 5, 6]
Output
[4, 5, 6]
Explanation
The middle nodes are 3 and 4; we return the list from the second middle node 4.
Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.