Coding Test: MCQ
Coding Test: MCQ
Coding Test: MCQ
MCQ:
1. What is the time complexity to count the number of elements in the
linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
2. Which of these is not an application of linked list?
a) To implement file systems
b) For separate chaining in hash-tables
c) To implement non-binary trees
d) Random Access of elements
3. In a circular linked list
a) Components are all linked together in some sequential manner.
b) There is no beginning and no end.
c) Components are arranged hierarchically.
d) Forward and backward traversal within the list is permitted.
4. The following function reverse() is supposed to reverse a singly linked
list. There is one line missing at the end of the function.
5. What is the output of following function for start pointing to first node
of following linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
a) 1 4 6 6 4 1
b) 1 3 5 1 3 5
c) 1 2 3 5
d) 1 3 5 5 3 1
6. Which of the following points is/are true about Linked List data
structure when it is compared with array
a) Arrays have better cache locality that can make them better in terms
of performance.
b) It is easy to insert and delete elements in Linked List
c) Random access is not allowed in a typical implementation of Linked
Lists
d)The size of array has to be pre-decided, linked lists can change their
size any time.
e) All Of the above.
a. Pointer to character
b. Pointer to integer
c. Pointer to node
d. Node
12.A variant of linked list in which last node of the list points to the first
node of the list is?
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Multiply linked list
Input:
First line of input contains number of testcases T. For each testcase, first
line of input contains length of linked list and next line contains the
linked list data.
Output:
For each testcase, there will be a single line of output which contains
linked list with no duplicates.
User Task:
The task is to complete the function removeDuplicates() which should
remove the duplicates from linked list. The printing is done
automatically by the driver code.
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)
Constraints:
1 <= T <= 100
1 <= N <= 104
Example:
Input:
2
4
2245
5
22222
Output:
245
2
Explanation:
Testcase 1: In the given linked list 2 ->2 -> 4-> 5, only 2 occurs more than
1 time.
Testcase 2: In the given linked list 2 ->2 ->2 ->2 ->2, 2 is the only element
and is repeated 5 times.
(OR)
15.Check if Linked List is Palindrome
Given a singly linked list of size N of integers. The task is to check if the
given linked list is palindrome or not.
Expected Time Complexity: O(N)
Expected Auxialliary Space Usage: O(1) (ie, you should not use the
recursive stack space as well)
Input:
First line of input contains number of testcases T. For each testcase, first
line of input contains length of linked list N and next line contains N
integers as data of linked list.
Output:
For each test case output will be 1 if the linked list is a palindrome else 0.
User Task:
The task is to complete the function isPalindrome() which takes head as
reference as the only parameter and returns true or false if linked list is
palindrome or not respectively.
Constraints:
1 <= T <= 103
1 <= N <= 50
Example:
Input:
2
3
121
4
1234
Output:
1
0
Explanation:
Testcase 1: The given linked list is 1 2 1 , which is a pallindrome and
Hence, the output is 1.
Testcase 2: The given linked list is 1 2 3 4 , which is not a pallindrome
and Hence, the output is 0.