Easiest/fastest solution in cpp

int Solution::solve(ListNode* A, int B) {
int n=0;
ListNode* temp=A;
while(temp){
    n=n+1;
    temp=temp->next;
}
int t=n/2 -B+1;
if(t<1){
    return -1;
}
ListNode* curr=A;
while(t>1){
    curr=curr->next;
    t--;
}
return curr->val;

}

Click here to start solving coding interview questions