Challenge: Find if Doubly Linked-list is a Palindrome
In this lesson, you will have to solve a coding challenge to find if a doubly linked-list is a palindrome.
We'll cover the following
Problem Statement
This challenge is easier to perform on a doubly linked-list with a tail pointer than on a singly linked-list. Let’s first see what a palindrome is. A palindrome is any string or sequence that reads the same from both ends. The following snippet shows examples of some palindromes.
RACECAR
MADAM
WOW
2002
You can extend this example to a linked-list as well. For example, the following linked-lists are palindromes:
List = 2<->0<->0<->2
List = 1<->2<->3<->2<->1
List = 1
The following ones are not palindrome:
List = 1<->2<->3
List = 2<->3
Method Prototype
public static boolean isPalindrome(DoublyLinkedList<T> list)
Output
Your function will return a boolean
variable; true
when linked-list is a palindrome, false
when it is not.
Sample Input
A doubly linked list with tail pointer
linkedlist = 1<->2<->3<->2<->1
Sample Output
true
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.