Home » Technical Interview Questions » LinkedList Interview Questions » Check if a linked list of strings form a palindrome

Check if a linked list of strings form a palindrome


Reading Time - 1 mins

Given a linked list handling string data, write a function to check whether the data forms a palindrom or not

Example

INPUT
ba->c->d->ca->b

OUTPUT
The string represented in above list is a palindrome

In the above example we can see that the string “bacdcab” is a palindrome

Algorithm

1. Construct a string from the data in all nodes in the linked list ie, use append() function

2. Traverse the string and compare respective first and last character ie, str[i] = str[length-i-1].If they are not equal, then it is not a palindrome.

READ  Detect a loop in the Linked List
Array Interview Questions
Graph Interview Questions
LinkedList Interview Questions
String Interview Questions
Tree Interview Questions