343. Find Pair with Given Sum in Doubly Linked List

EasyLinked ListDoubly Linked ListTwo PointerHashing

Given a sorted doubly linked list and an integer target, find all pairs [a, b] where a + b = target and a <= b.

Use the two-pointer technique.

Input: Sorted doubly linked list (as array) and integer target.

Output: List of [a, b] pairs sorted by first element.

Examples

Example 1
Input: [-10,-3,1,3,5,8,11], 8
Output: [[-3,11],[3,5]]
Explanation: (-3+11=8), (3+5=8).
Example 2
Input: [1,2,3,4,5], 5
Output: [[1,4],[2,3]]
Explanation: (1+4=5), (2+3=5).
Example 3
Input: [1,2,3,4,5], 10
Output: []
Explanation: No pair sums to 10.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →