Java Program To Check If A Linked List Of Strings Forms A Palindrome Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. The idea is very simple. Construct a string out of given linked list and check if the constructed string is palindrome or not. Java // Java Program to check if a given linked list // of strings form a palindrome import java.util.Scanner; // Linked List node class Node { String data; Node next; Node(String d) { data = d; next = null; } } class LinkedList_Palindrome { Node head; // A utility function to check if // str is palindrome or not boolean isPalidromeUtil(String str) { int length = str.length(); // Match characters from beginning // and end. for (int i = 0; i < length / 2; i++) if (str.charAt(i) != str.charAt(length - i - 1)) return false; return true; } // Returns true if string formed by // linked list is palindrome boolean isPalindrome() { Node node = head; // Append all nodes to form a // string String str = ""; while (node != null) { str = str.concat(node.data); node = node.next; } // Check if the formed string is // palindrome return isPalidromeUtil(str); } // Driver code public static void main(String[] args) { LinkedList_Palindrome list = new LinkedList_Palindrome(); list.head = new Node("a"); list.head.next = new Node("bc"); list.head.next.next = new Node("d"); list.head.next.next.next = new Node("dcb"); list.head.next.next.next.next = new Node("a"); System.out.println(list.isPalindrome()); } } // This code is contributed by Amit Khandelwal Output: true Time Complexity: O(n), where n is the number of nodes in the given linked list.Auxiliary Space: O(m) where m is the length of the string formed by the linked list. Please refer complete article on Check if a linked list of strings forms a palindrome for more details! Comment More infoAdvertise with us Next Article Java Program To Check If A Linked List Of Strings Forms A Palindrome kartik Follow Improve Article Tags : Linked List Java Programs DSA palindrome Practice Tags : Linked Listpalindrome Similar Reads Java Program For Checking Linked List With A Loop Is Palindrome Or Not Given a linked list with a loop, the task is to find whether it is palindrome or not. You are not allowed to remove the loop. Examples: Input: 1 -> 2 -> 3 -> 2 /| |/ ------- 1 Output: Palindrome Linked list is 1 2 3 2 1 which is a palindrome. Input: 1 -> 2 -> 3 -> 4 /| |/ ------- 1 4 min read Java Program to Check Whether a String is a Palindrome A string in Java can be called a palindrome if we read it from forward or backward, it appears the same or in other words, we can say if we reverse a string and it is identical to the original string for example we have a string s = "jahaj " and when we reverse it s = "jahaj"(reversed) so they look 8 min read Java Program to Find All Palindromic Sub-Strings of a String Given a string, the task is to count all palindrome substring in a given string. Input : aba Output : 4 Explanation : All palindrome substring are : "aba" , "a" , "b", "a" Input : TENET Output : 7 Explanation : All palindrome sub-string are : "T" , "E" , "N", "E", "T" , "ENE" , "TENET" Approach: Tak 2 min read Find all palindromic sub-strings of a given string | Set 2 Given a string, the task is to find all the palindromic sub-strings from the given string.In Set - 1, another approach has been already discussed and that consider only distinct sub-strings but in this equal sub-strings i.e. ll and ll are considered as two sub-strings, not one. Examples: Input : hel 7 min read Palindrome Number Program in Java A given number can be said to be palindromic if the reverse of the given number is the same as that of a given number. In this article, we will write a Program to check if a number is a Palindrome Number in Java.Example of Palindrome Number:Input : n = 121Output: Reverse of n = 121Palindrome : YesIn 7 min read C Program To Check If A Linked List Of Strings Forms A Palindrome Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco 2 min read Python Program To Check If A Linked List Of Strings Forms A Palindrome Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco 2 min read Check if a linked list of strings forms a palindrome Given a linked list handling string data, check to see whether data is palindrome or not? For example, Input : a -> bc -> d -> dcb -> a -> NULL Output : True String "abcddcba" is palindrome. Output : a -> bc -> d -> ba -> NULL Output : False String "abcdba" is not palindro 6 min read C++ Program To Check If A Singly Linked List Is Palindrome Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. METHOD 1 (Use a Stack): A simple solution is to use a stack of list nodes. This mainly invol 9 min read C Program To Check If A Singly Linked List Is Palindrome Given a singly linked list of characters, write a function that returns true if the given list is a palindrome, else false. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution. METHOD 1 (By reversing the list): This method takes O(n) time and O(1) extra space. 1) Get t 7 min read Like