Given a singly linked list. The task is to find the length of linked list, where length is defined as number of nodes in the linked list.

Input:
First line of input contains number of testcases T. For each testcase, first line of input contains number of nodes N, to be inserted into the linked list and next line contains data of N nodes.

Output:
There will be a single line of output for each testcase, which contains length of the linked list.

Constraints:
1 <= T <= 30
1 <= N <= 100
1 <= value <= 103

User Task:
Your task is to complete the given function getCount(), which takes head reference as argument and should return the length of linked list.

Example:
Input:

2
5
1 2 3 4 5
7
2 4 6 7 5 1 0

Output:
5
7

Explanation:
Testcase 1: Count of nodes in the linked list is 5, which is its length.

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: atharv


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.