As reported: Microsoft SDE-2 L62 (Hyderabad, Jan 2025), round 1 (DSA), question 2: given an even-sized linked list, return the maximum twin sum, where a twin sum is
list(i) + list(n − 1 − i). Modifying the list was not allowed; the interviewer hinted at using extra space, and slow/fast pointers while storing the first half in an array of sizen/2was accepted.
In a linked list of even length n, node i (0-indexed) and node n − 1 − i are twins. Their twin sum is the sum of their values. Return the maximum twin sum. Do not modify the list.
This is LeetCode 2130 — Maximum Twin Sum of a Linked List.
Example 1
head = [5,4,2,1] -> 6 (5 + 1 and 4 + 2)
Example 2
head = [4,2,2,3] -> 7 (4 + 3)
Example 3
head = [1,100000] -> 100001
Constraints: the number of nodes is even, 2 … 10^5; 1 ≤ Node.val ≤ 10^5.
Code runner format: one JSON value per line: head as an array (LeetCode's test-case format). Implement pairSum(head); the harness prints the result.