

The length of the list is 4. Hence we return 4.
Exercise caution when dealing with edge cases, such as when the head is NULL. Failing to handle these edge cases appropriately may result in a runtime error in your code.
The first and only line contains elements of the singly linked list separated by a single space, -1 indicates the end of the singly linked list and hence, would never be a list element.
Return a single integer denoting the length of the linked list.
The basic idea of this approach is to traverse the linked list.
Now consider the following steps: