# Find Pairs

Contributed by
Omkar Deshmukh
Last Updated: 23 Feb, 2023
Easy
0/40
Avg time to solve 18 mins
Success Rate 75 %
Share

## Problem Statement

#### We are given a sorted doubly-linked list which contains distinct positive integers, and an integer ‘X’. Print all such unique pairs from the given list so that their sum is equal to ‘X’.

Detailed explanation ( Input/output format, Notes, Images )
##### Constraints :
``````1 <= N <= 5*10^5
-2*10^9 <= X <= 2*10^9
-10^9 <= data <= 10^9 and data != -1

Where ‘N’ is the length of the linked list and ‘X’ is the required pair sum value.

Time Limit: 1 sec
``````
##### Sample Input 1:
``````2 7 10 14 15 19 22 27 -1
29
``````
##### Sample Output 1:
``````2 27
7 22
10 19
14 15
``````
##### Explanation For Sample Input 1:
``````There are four such pairs possible (2, 27), (7, 22), (10, 19), (14, 15) whose sum is 29.
``````
##### Sample Input 2:
``````1 4 7 9 11 21 23 29 31 37 41 43 45 48 -1
52
``````
##### Sample Output 2:
``````4 48
7 45
9 43
11 41
21 31
23 29
``````
##### Explanation For Sample Input 2:
``````There are six such pairs possible (3, 48), (7, 45), (9, 43), (11, 41), (21, 31), (23, 29) whose sum is 52.
``````
Auto
Console