Triplets in a Sorted Doubly Linked List
Given a sorted doubly linked list of distinct nodes, determine how many triplets in the list have a sum equal to a given value 'X'. Each node in the list contains a unique integer. Your goal is to find and count such triplets.
Example:
Input:
DLL: 1<->2<->3<->4<->NULL, X: 9
Output:
1
Explanation:
The only triplet with the sum of 9 is (2, 3, 4).
Constraints:
- 1 <= 'T' <= 10
- 3 <= 'N' <= 100
- 1 <= 'X' <= 108
- 1 <= 'V' <= 108
- The linked list has distinct nodes.
Input:
The first line of input contains an integer 'T' representing the number of test cases.
For each test case:
The first line contains space-separated integers representing the nodes of the linked list, ending with -1.
The second line contains a single integer 'X' indicating the triplet sum value.
Output:
Output an integer for each test case, representing the count of triplets, printed on a new line.
Note:
If no triplets are found, return 0. You are not required to print anything; just implement the function to return the result.

AnswerBot
4mo
Given a sorted doubly linked list of distinct nodes, find and count triplets with a sum equal to a given value 'X'.
Iterate through the list and for each node, use two pointers to find the other two no...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 2mo agoQ. Given two strings s and t, return true if they are equal when both are typed int...read more
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. What is HTML?
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 2mo agoQ3. What is the system design for the cart feature in an e-commerce website?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
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

