Find Pairs with given Sum in DLL
Medium Problems of Doubly Linked List DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Find pairs with given sum in DLL, Data Structures, Linked List, Doubly Linked List, Node, Pointer, Hashing, Hash Tables, Two Pointers, Time Complexity, Space Complexity, Big O Notation, Loops, Conditional Statements, Algorithm, searching, complexity analysis, linked list, two pointer technique, Linked List, Finding Pairs with a Given Sum.
Problem Statement: You are given the head of a Doubly Linked List and an integer target sum. Your task is to find all pairs of nodes in the Doubly Linked List such that their values sum up to the target sum. Each pair (node1.val, node2.val) should be unique, meaning if (A, B) is a pair, then (B, A) should not be listed as a separate pair. Pairs should be listed in non decreasing order of the first element. If no such pairs exist, an empty list should be returned. Input Specification: head: A pointer to the head of the Doubly Linked List. Each node has an integer val, a next pointer, and a prev pointer. target sum: An integer representing the target sum. Output Specification: Return a list of lists, where each inner list [val1, val2] represents a pair of values that sum up to target sum. Constraints: The number of nodes in the Doubly Linked List N will be between 0 and 10^5. Node values will be between 10^9 and 10^9. target sum will be between 2 10^9 and 2 10^9. Sample Test Case: Input: Output: Explanation: 1 + 6 = 7 2 + 5 = 7 3 + 4 = 7