Getting wrong output

i tried the code myself and getting wrong output can you please check my code and please tell me what mistake i am doing in my code

Hey @shivamgoel150

ll mid(node*head)
{
    if(head==NULL)return -1;//addec corner case
    node*fast=head;
    node*slow=head;

    ll cnt=0;
    while(fast!=NULL)
    {
        if(cnt<2) //<2 here
        {
            fast=fast->next;
            cnt++;
        }

        else
        {
            slow=slow->next;
            fast=fast->next;
            cnt=1;
        }
    }

    return slow->data;
}

or easier way

ll mid(node*head)
{   
    if(head==NULL)return -1;//added corner case
    node*fast=head->next;
    node*slow=head;

    ll cnt=0;
    while(fast!=NULL&&fast->next!=NULL)
    {
           slow=slow->next;
            fast=fast->next->next;
        }

    return slow->data;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.