Palindrome Linked List Detection
Given a singly linked list of integers, determine if it is a palindrome. A linked list is considered a palindrome if it reads the same forward and backward.
Example:
Input:
The given linked list is 1 -> 2 -> 3 -> 2 -> 1 -> NULL.
Output:
true
Explanation:
The linked list is a palindrome because it reads the same when traversed forwards and backwards.
Input:
The first line of input contains an integer 'T', representing the number of test cases. Each test case consists of one line where elements of the singly linked list are separated by a space and end with -1, which is not part of the list.
Output:
For each test case, return "true" or "false" on a new line.
Example:
Input:
2
1 2 3 2 1 -1
1 2 3 -1
Output:
true
false
- 1 ≤ T ≤ 10
- 0 ≤ L ≤ 105
- 1 ≤ data ≤ 109 and data ≠ -1
Note: You do not have to print anything, just implement the given function.
Follow up: Can you solve this in O(N) time complexity and O(1) space complexity iteratively?

AnswerBot
4mo
Check if a singly linked list is a palindrome by comparing elements from both ends.
Traverse the linked list to find the middle point
Reverse the second half of the linked list
Compare the first half wit...read more
Help your peers!
Add answer anonymously...
American Express Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
A Software Developer Intern was asked Q. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
A Software Developer Intern was asked Q. Maximum Non-Adjacent Subsequence Sum Given an array of integers, determine the m...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
A Software Developer Intern was asked Q2. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
A Software Developer Intern was asked Q3. Maximum Non-Adjacent Subsequence Sum Given an array of integers, determine the m...read more
>
American Express Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

