
Asked in Bank of America
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.

AnswerBot
4mo
Find pairs in a sorted doubly-linked list whose sum equals a given integer 'X'.
Traverse the list from both ends to find pairs with sum equal to 'X'.
Use two pointers approach to efficiently find the pa...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Bank of America
Q. How do you find the length of an array?
Q. Given two strings needle and haystack, return the index of the first occurrence ...read more
Q. What are some basic JavaScript questions?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Bank of America Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

