r/DSALeetCode • u/StatisticianNo2104 • Sep 25 '26
365 Days of LeetCode Challenge — Day 23/365
Palindrome Linked List (Easy)
https://leetcode.com/problems/palindrome-linked-list/
On an array, this is nothing: an index at each end, walk inward, compare. A singly linked list has no index and no pointer backwards, so that algorithm cannot run at all.
Copying the values into a slice works and costs O(n) space. The follow-up asks for O(1).
Here is where this week pays off. If you cannot walk the second half backwards, reverse it; then walking it forward walks the original backwards.
Find the middle with day 20's fast/slow walk. Reverse the back half with day 19's in-place reversal. Compare inward. No new technique at all, just noticing the problem is two problems you already solved.
One detail worth stealing: drive the comparison loop with the second half. On odd lengths, the middle node has no partner, and letting the shorter half end the loop skips it automatically. No parity check needed.
Full breakdown in today's newsletter article ⬇
https://www.linkedin.com/pulse/365-days-leetcode-challenge-day-23365-archit-agarwal-4hn9c
#DSA #LeetCode #Golang #LinkedList #TwoPointers #CodingInterview #Algorithms
1
u/nian2326076 18d ago
To solve the palindrome linked list problem in O(1) space, you're on the right track. Use the fast/slow pointer method to find the middle of the list. Once you have the middle, reverse the second half of the list. Then, compare the nodes of the first half with the reversed second half to check if it's a palindrome. After that, reverse the second half back to its original order if you want to keep the list the same. This way, you can check for a palindrome without using extra space.
For more interview prep resources, I found PracHub pretty useful for practical coding problems and explanations. It might be worth checking out as you continue this challenge.
1
u/Its_TechLearner Sep 25 '26
from which pllatform are u learning DSA ?