Skip to main content
Back to problems
Leetcode
Medium
Linked Lists
Two Pointers
Stacks
Meta
Google
Maximum Twin Sum of a Linked List

Find the maximum twin sum in an even-length linked list.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

2130. Maximum Twin Sum of a Linked List

gfg
Problem Statement

You are given the head of a singly linked list with an even number of nodes.

For each node at position ii from the start, its twin is the node at position n−1−in - 1 - i from the start, where nn is the number of nodes in the list.

A twin sum is the sum of values of a node and its twin. Return the largest twin sum among all pairs.

Input Format

A singly linked list head representing an even-length list of integer values.

Output Format

Return a single integer: the maximum twin sum over all mirrored pairs.

Constraints

• The list contains an even number of nodes. • Node values are integers. • Aim for O(n)O(n) time. • Extra space should be minimized when possible.

Examples
Sample cases returned by the problem API.

Example 1

Input

head = [5,4,2,1]

Output

6

Explanation

The twin pairs are (5,1) and (4,2). Their sums are 6 and 6, so the maximum twin sum is 6.

Example 2

Input

head = [4,2,2,3]

Output

7

Explanation

The twin pairs are (4,3) and (2,2). Their sums are 7 and 4, so the answer is 7.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.