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

Check if a linked list of strings form a palindrome


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.

vote
Article Rating
READ  Swap nodes in the linked list
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x