Ctrl K

Mirror Pairs in a List

Medium
You get a singly linked list of even length n whose first node is first. Nodes are numbered from zero. Node i and node n - 1 - i form a *mirror pair*: the first with the last, the second with the second-to-last, and so on. The sum of a pair is the sum of its two node values. Return the largest sum over all mirror pairs.
Example 1
first=list_node([3, 8, 1, 6]) → 9

The pairs are the first and last nodes, 3 + 6 = 9, and the second and third, 8 + 1 = 9. The maximum is 9.

Example 2
first=list_node([2, 10, 4, 7, 1, 5]) → 11

The pairs are 2 + 5 = 7, 10 + 1 = 11 and 4 + 7 = 11. The answer is 11.

Example 3
first=list_node([50, 50]) → 100
Constraints
  • The number of nodes is even, between 2 and 10⁵
  • 1 ≤ Node.val ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsList Folded From Both Ends MediumSymmetric Bead String EasyDrop the K-th Node From the Tail MediumMove the Tail to the Front MediumSorted List, Unique Values Only Medium
loading Python…
Input
first=list_node([3, 8, 1, 6])
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.