
Asked in Practo
Palindrome Linked List Problem Statement
You are provided with a singly linked list of integers. Your task is to determine whether the given singly linked list is a palindrome. Return true
if it is a palindrome, otherwise return false
.
Example:
Input:
1 -> 2 -> 3 -> 2 -> 1 -> NULL
Output:
true
Explanation:
The given linked list maintains the same sequence of elements when traversed forwards and backwards, hence it is a palindrome.
Constraints:
1 <= T <= 10
0 <= L <= 10^5
1 <= data <= 10^9
(anddata != -1
)
Input:
The first line of input contains an integer 'T' representing the number of test cases. For each test case, the only line contains the elements of the singly linked list separated by a space, ending with -1. Note that -1 is not part of the list.
Output:
For each test case, output 'true' or 'false' in a new line, indicating whether the linked list is a palindrome or not.
Note:
You do not need to print anything as it is managed within the implementation. Simply complete the provided function.
Follow Up:
Can you devise a solution with O(N) time complexity and O(1) space complexity iteratively?

AnswerBot
4mo
Check if a given singly linked list is a palindrome or not.
Traverse the linked list to find the middle element using slow and fast pointers.
Reverse the second half of the linked list.
Compare the first...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Practo
Q. Given a table "student" with columns Name and Marks, write an SQL query to get t...read more
Q. Given a function toss() that returns head or tail with equal probability, what c...read more
Q. What is left join. Give example. And Full outer join?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Practo Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

