
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of every test case contains the elements of the doubly linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
The second line of every test case contains the value of x.
For each test case, print the count of triplets.
The output of each test case is printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
3 <= N <= 100
-10^8 <= data <= 10^8 and data != -1
-3*10^8 <= x <= 3*10^8
Where T is the number of test cases, N is the length of the doubly linked list and x is the given value of the sum.
The simplest way is to go through all the possible triplets and incrementing count by 1 whenever any desired triplet is found.
It is given that the doubly linked list is sorted, we can use this property by applying the two pointer approach. The idea is to traverse the doubly linked list from left to right, and for each current node during the traversal, initialize two pointers first and last. The first pointer will be pointing to the node just next to the current node and the last pointer will be pointing to the end node of the linked list. Count the pairs, using these two pointers, whose sum is equal to ‘x - current node’s data’ and add this count to the total count of triplets. Return the total count.
Rock Paper Scissor
Rock Paper Scissor
Rock Paper Scissor
Rock Paper Scissor
Longest Palindromic Substring
Implement Queue using Arrays
Find the direction from given string
Subarray Median Queries