Length of longest palindrome in linked list
Submissions: 6109   Accuracy:


  Difficulty: Medium   Marks: 4
Associated Course(s):   Sudo Placement 2019

Given a linked list, the task is to complete the function maxPalindrome which returns an integer denoting  the length of the longest palindrome list that exist in the given linked list.


Input  : List = 2->3->7->3->2->12->24
Output : 5
The longest palindrome list is 2->3->7->3->2

Input  : List = 12->4->4->3->14
Output : 2
The longest palindrome list is 4->4

The first line of input contains an integer T denotingo the no of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of the linked list . Then in the next line are N space separated values of the given linked list.

For each test case output will be the required max length of the palindrome present in the given linked list.


Example(To be used only for expected output):

2 3 7 3 2 12 24
12 4 4 3 14

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.