Find Pairs in a Doubly-Linked List
A sorted doubly-linked list of distinct positive integers is provided, along with an integer 'X'. Your task is to identify and print all unique pairs from the list whose sum equals 'X'.
Example:
Input:
10 20 35 50 75 -1
55
Output:
20 35
Constraints:
1 <= N <= 5*105
-2*109 <= X <= 2*109
-109 <= data <= 109
anddata != -1
Input:
The first line contains elements of the doubly linked list, separated by spaces and terminated by -1 (which is not an element of the list).
The second line contains the integer 'X'.
Output:
For each unique pair where the sum is equal to 'X', print the pair in such a way that the first element is less than the second. Each pair should appear on a separate line, and the order of pairs does not matter.
Note:
No need to handle printing within the function. Simply implement the logic to return the answer.
Follow-Up:
Attempt to solve the problem with linear time complexity without utilizing additional data structures.
Be the first one to answer
Add answer anonymously...
Top Goldman Sachs Software Analyst interview questions & answers
Popular interview questions of Software Analyst
>
Goldman Sachs Software Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app