Check If a Linked List is Palindrome or Not

In this tutorial, I am going to discuss a programming question Palindrome linked list and it’s implementation using java code.

Given a singly linked list, Write a code that returns true if the given linked list is a Palindrome else return false.

For example –

Example 1 –

1 -> 3 -> 4 -> 3 -> 1 -> NULL

It’s a palindrome.

Example 2 –

1 -> 3 -> 4 -> NULL

It’s not a palindrome.

NOTE: We have to solve this problem in O(n) time complexity and without using any extra space.

Remove Nth Node from the End of a Linked List

Given a singly linked list, write a code to remove nth node from the end of a linked list. In this problem, you can assume the value of n is always valid.

For example –

In this example, the input linked list has four nodes and we have to remove 2nd node from the end.

Input –

15 -> 9 -> 8 -> 5 -> NULL , N = 2

After removing second node (node whose value is 8) from the end, the output is

15 -> 9 -> 5 -> NULL

Reverse a Linked List

Given a singly linked list, write a code to reverse a linked list. In this tutorial, you are going to learn how to reverse a linked list in java using iterative approach.

For example –

Input linked list.

15 -> 9 -> 8 -> 5 -> NULL

When we reverse this linked list then the output is given below.

5 -> 8 -> 9 -> 15 -> NULL

In input linked list, head points to a node whose value is 15 but when it’s reversed the head points to a node whose value is 5.