public class Solution {
public static int countAllTripletSum(Node head, int x) {
// Write your code here.
Node temp = head;
int count = 1;
while(temp!=null && temp.next!=null){
temp=temp.next;
count++;
}
if(count<=2){
return 0;
}
int curr=0,res=0;
Node h,t;
while(head!=temp){
curr=x-head.data;
h=head.next;
t=temp;
while(h!=t && h.prev!=t){
if((h.data + t.data) == curr){
res++;
t=t.prev;
h=h.next;
}else if((h.data + t.data) > curr){
t=t.prev;
}else{
h=h.next;
}
}
head=head.next;
}
return res;
}
}