Problem
You get the head of a linked list with an even number of nodes n. The nodes have the positions 0 to n - 1.
The twin of the node at position i is the node at position n - 1 - i. For example, in a list of 6 nodes, the nodes at positions 0 and 5 are twins. The nodes at positions 1 and 4 are also twins.
The twin sum is the value of a node plus the value of its twin. Return the largest twin sum in the list.
Example 1
- Input:
- head = [3,8,2,6]
- Output:
- 10
- Explanation:
- The twin sums are
3 + 6 = 9and8 + 2 = 10. The largest twin sum is 10.
Example 2
- Input:
- head = [4,1,7,5,2,3]
- Output:
- 12
- Explanation:
- The twin sums are 7, 3 and 12.
Example 3
- Input:
- head = [1,9]
- Output:
- 10
Constraints
- The number of nodes n is even.
- 2 <= n <= 10^5
- 1 <= Node.val <= 10^5
Follow-up
Find the answer with O(1) extra memory.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Remove Zero Sum Consecutive Nodes from Linked List
Coding
- Binary Tree Maximum Path Sum
Coding · Binary Tree · Depth-First Search · DP on Trees
- Choose K Elements With Maximum Sum
Coding
- Convert Binary Number in a Linked List to Integer
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 2130. Maximum Twin Sum of a Linked List
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source