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.
Be the first one to answer
Add answer anonymously...
Top Amazon Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amazon Software Developer
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