-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked List Length Even or Odd
35 lines (28 loc) · 1.88 KB
/
Linked List Length Even or Odd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Linked List Length Even or Odd?
## Easy
<div class="problems_problem_content__Xm_eO"><p><span style="font-size:18px">Given a linked list of size <strong>N</strong>, your task is to complete the function <strong>isLengthEvenOrOdd() </strong>which contains <strong>head</strong> of the linked list and check whether the length of linked list is even or odd.</span></p>
<p><span style="font-size:18px"><strong>Input:</strong><br>
The input line contains <strong>T</strong>, denoting the number of testcases. Each testcase contains two lines. the first line contains <strong>N</strong>(size of the linked list). the second line contains N elements of the linked list separated by space.</span></p>
<p><span style="font-size:18px"><strong>Output:</strong><br>
For each testcase in new line, print "<strong>even</strong>"(without quotes) if the length is even else "<strong>odd</strong>"(without quotes) if the length is odd.</span></p>
<p><span style="font-size:18px"><strong>User Task:</strong><br>
Since this is a functional problem you don't have to worry about input, you just have to complete the function <strong>isLengthEvenOrOdd() </strong>which takes head of the linked list as input parameter and returns 0 if the length of the linked list is even otherwise returns 1.</span></p>
<p><span style="font-size:18px"><strong>Constraints:</strong><br>
1 <= T <= 100<br>
1 <= N <= 10<sup>3</sup><br>
1 <= A[i] <= 10<sup>3</sup></span></p>
<p><span style="font-size:18px"><strong>Example:<br>
Input:</strong><br>
2<br>
3<br>
9 4 3<br>
6<br>
12 52 10 47 95 0</span></p>
<p><span style="font-size:18px"><strong>Output:</strong><br>
Odd<br>
Even</span></p>
<p><span style="font-size:18px"><strong>Explanation:<br>
Testcase 1: </strong>The length of linked list is 3 which is odd.<br>
<strong>Testcase 2</strong>: The length of linked list is 6 which is even.</span><br>
</p>
</div>