0% found this document useful (0 votes)
5 views2 pages

Linked List Problem Set Solutions

The document outlines a set of linked list problems with corresponding inputs and outputs. It includes tasks such as printing the size of a linked list, finding the middle node, counting occurrences of a number, inserting into a sorted list, deleting even numbers, reversing lists, rotating lists, checking for palindromes, and detecting cycles. Each problem is presented with example input and expected output for clarity.

Uploaded by

nurerenerafi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Linked List Problem Set Solutions

The document outlines a set of linked list problems with corresponding inputs and outputs. It includes tasks such as printing the size of a linked list, finding the middle node, counting occurrences of a number, inserting into a sorted list, deleting even numbers, reversing lists, rotating lists, checking for palindromes, and detecting cycles. Each problem is presented with example input and expected output for clarity.

Uploaded by

nurerenerafi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Linked list problem set

1. Print the size of a linked list.

Input Output

34->12->55->42->11 5

2. Given the head of a linked list, print the value of the middle node.

Input Output

34->12->55->42->11 55

12->8->65->10 8

3. Print the number of occurrences of a given number in a linked list.

Input Output

1->2->1->2->1->3->1, num = 1 4

4. Given a sorted linked list, insert a number so that after insertion, it remains
sorted.

Input Output

1->4->6->7->9->11, num = 3 1->3->4->6->7->9->11

5. Delete all the even numbers from a linked list.

Input Output

1->4->6->7->9->11 1->7->9->11

6. Reverse a doubly linked list.

Input Output

7<->12<->8<->65<->10 10<->65<->8<->12<->7
7. Reverse a singly linked list.

Input Output

7->12->8->65->10 10->65->8->12->7

8. Given a singly linked list and an integer k, rotate the linked list to the left by k
places.

Input Output

10->20->30->40->50, k = 4 50->10->20->30->40

9. Given a singly linked list, print “YES” if it is a palindrome otherwise print “NO”.

Input Output

1->2->2->1 YES

1->2->3->1 NO

10. Given the head of a linked list, determine if the linked list has a cycle in it.

Input Output

3->2->0->4 Yes
| |
1<-6

3->2->0->4->NULL NO

You might also like