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