Practice 50 JavaScript Linked List Programming Questions
Q1. Write a JavaScript program to create a singly linked list and display its elements.
Input: list = [1, 2, 3]
Expected Output: 1 -> 2 -> 3
Q2. Write a JavaScript program to insert a node at the beginning of a linked list.
Input: list = [2, 3], value = 1
Expected Output: 1 -> 2 -> 3
Q3. Write a JavaScript program to insert a node at the end of a linked list.
Input: list = [1, 2], value = 3
Expected Output: 1 -> 2 -> 3
Q4. Write a JavaScript program to delete a node at the beginning of a linked list.
Input: list = [1, 2, 3]
Expected Output: 2 -> 3
Q5. Write a JavaScript program to delete a node at the end of a linked list.
Input: list = [1, 2, 3]
Expected Output: 1 -> 2
Q6. Write a JavaScript program to search for an element in a linked list.
Input: list = [1, 2, 3], value = 2
Expected Output: true
Q7. Write a JavaScript program to reverse a singly linked list.
Input: list = [1, 2, 3]
Expected Output: 3 -> 2 -> 1
Q8. Write a JavaScript program to find the middle element of a linked list.
Input: list = [1, 2, 3, 4, 5]
Expected Output: 3
Q9. Write a JavaScript program to find the length of a linked list.
Input: list = [1, 2, 3, 4]
Expected Output: 4
Q10. Write a JavaScript program to remove duplicate elements from a linked list.
Input: list = [1, 2, 2, 3, 4, 4]
Expected Output: 1 -> 2 -> 3 -> 4
Q11. Write a JavaScript program to detect if a linked list has a cycle.
Input: list = [1, 2, 3, 4], cycle = true
Expected Output: true
Q12. Write a JavaScript program to merge two sorted linked lists.
Input: list1 = [1, 3, 5], list2 = [2, 4, 6]
Expected Output: 1 -> 2 -> 3 -> 4 -> 5 -> 6
Q13. Write a JavaScript program to remove the nth node from the end of a linked list.
Input: list = [1, 2, 3, 4, 5], n = 2
Expected Output: 1 -> 2 -> 3 -> 5
Q14. Write a JavaScript program to find the nth node from the end of a linked list.
Input: list = [1, 2, 3, 4, 5], n = 2
Expected Output: 4
Q15. Write a JavaScript program to create a doubly linked list and display its elements.
Input: list = [1, 2, 3]
Expected Output: 1 <-> 2 <-> 3
Q16. Write a JavaScript program to insert a node at a specific position in a linked list.
Input: list = [1, 2, 3], value = 4, position = 2
Expected Output: 1 -> 4 -> 2 -> 3
Q17. Write a JavaScript program to delete a node at a specific position in a linked list.
Input: list = [1, 2, 3, 4], position = 2
Expected Output: 1 -> 3 -> 4
Q18. Write a JavaScript program to check if two linked lists are equal.
Input: list1 = [1, 2, 3], list2 = [1, 2, 3]
Expected Output: true
Q19. Write a JavaScript program to copy a linked list.
Input: list = [1, 2, 3]
Expected Output: 1 -> 2 -> 3
Q20. Write a JavaScript program to remove all nodes with a specific value from a linked list.
Input: list = [1, 2, 3, 4], value = 3
Expected Output: 1 -> 2 -> 4
Q21. Write a JavaScript program to implement a stack using a linked list.
Input: push(1), push(2), pop()
Expected Output: 2
Q22. Write a JavaScript program to implement a queue using a linked list.
Input: enqueue(1), enqueue(2), dequeue()
Expected Output: 1
Q23. Write a JavaScript program to sort a linked list.
Input: list = [3, 1, 4, 2]
Expected Output: 1 -> 2 -> 3 -> 4
Q24. Write a JavaScript program to find the intersection of two linked lists.
Input: list1 = [1, 2, 3], list2 = [2, 3, 4]
Expected Output: 2 -> 3
Q25. Write a JavaScript program to find the union of two linked lists.
Input: list1 = [1, 2, 3], list2 = [3, 4, 5]
Expected Output: 1 -> 2 -> 3 -> 4 -> 5
Q26. Write a JavaScript program to find the difference between two linked lists.
Input: list1 = [1, 2, 3], list2 = [3, 4, 5]
Expected Output: 1 -> 2
Q27. Write a JavaScript program to create a linked list from an array.
Input: arr = [1, 2, 3]
Expected Output: 1 -> 2 -> 3
Q28. Write a JavaScript program to convert a linked list to an array.
Input: list = [1, 2, 3]
Expected Output: [1, 2, 3]
Q29. Write a JavaScript program to check if a linked list is a palindrome.
Input: list = [1, 2, 3, 2, 1]
Expected Output: true
Q30. Write a JavaScript program to find the sum of all elements in a linked list.
Input: list = [1, 2, 3]
Expected Output: 6
Q31. Write a JavaScript program to find the maximum value in a linked list.
Input: list = [1, 2, 3, 4]
Expected Output: 4
Q32. Write a JavaScript program to find the minimum value in a linked list.
Input: list = [1, 2, 3, 4]
Expected Output: 1
Q33. Write a JavaScript program to implement a doubly linked list and perform insertion and deletion operations.
Input: insert(1), insert(2), delete(1)
Expected Output: 2
Q34. Write a JavaScript program to remove a node with a specific value from a doubly linked list.
Input: list = [1, 2, 3], value = 2
Expected Output: 1 <-> 3
Q35. Write a JavaScript program to merge two sorted doubly linked lists.
Input: list1 = [1, 3, 5], list2 = [2, 4, 6]
Expected Output: 1 <-> 2 <-> 3 <-> 4 <-> 5 <-> 6
Q36. Write a JavaScript program to swap adjacent nodes in a linked list.
Input: list = [1, 2, 3, 4]
Expected Output: 2 -> 1 -> 4 -> 3
Q37. Write a JavaScript program to remove all nodes with even values from a linked list.
Input: list = [1, 2, 3, 4, 5]
Expected Output: 1 -> 3 -> 5
Q38. Write a JavaScript program to check if a linked list is circular.
Input: list = [1, 2, 3], circular = true
Expected Output: true
Q39. Write a JavaScript program to count the occurrences of a specific value in a linked list.
Input: list = [1, 2, 3, 1], value = 1
Expected Output: 2
Q40. Write a JavaScript program to find the second largest element in a linked list.
Input: list = [1, 2, 3, 4]
Expected Output: 3
Q41. Write a JavaScript program to move all zeroes in a linked list to the end.
Input: list = [0, 1, 0, 2, 3]
Expected Output: 1 -> 2 -> 3 -> 0 -> 0
Q42. Write a JavaScript program to implement a linked list with a function to display the data in reverse.
Input: list = [1, 2, 3]
Expected Output: 3 -> 2 -> 1
Q43. Write a JavaScript program to insert a node after a specific node in a linked list.
Input: list = [1, 2, 3], node = 2, value = 4
Expected Output: 1 -> 2 -> 4 -> 3
Q44. Write a JavaScript program to find the intersection point of two linked lists.
Input: list1 = [1, 2, 3, 4], list2 = [5, 6, 7, 8], intersection = 3
Expected Output: 3 -> 4
Q45. Write a JavaScript program to implement a function to merge two linked lists alternately.
Input: list1 = [1, 3, 5], list2 = [2, 4, 6]
Expected Output: 1 -> 2 -> 3 -> 4 -> 5 -> 6
Q46. Write a JavaScript program to split a linked list into two halves.
Input: list = [1, 2, 3, 4, 5]
Expected Output: list1 = [1, 2, 3], list2 = [4, 5]
Q47. Write a JavaScript program to check if a linked list is sorted.
Input: list = [1, 2, 3, 4]
Expected Output: true
Q48. Write a JavaScript program to check if a linked list contains a cycle using Floyd's cycle-finding algorithm.
Input: list = [1, 2, 3, 4], cycle = true
Expected Output: true
Q49. Write a JavaScript program to implement a linked list and add a function to print every second node.
Input: list = [1, 2, 3, 4, 5]
Expected Output: 2 -> 4
Q50. Write a JavaScript program to add a function that finds the intersection of two linked lists.
Input: list1 = [1, 2, 3], list2 = [2, 3, 4]
Expected Output: 2 -> 3
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!